{"record":{"id":"64a0b37d66afde5c","repo":"Mintplex-Labs/anything-llm","slug":"no-gemini-api-key-was-set-64a0b3","errorCode":null,"errorMessage":"No Gemini API key was set.","messagePattern":"No Gemini API key was set\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"server/utils/EmbeddingEngines/gemini/index.js","lineNumber":11,"sourceCode":"const { toChunks, reportEmbeddingProgress } = require(\"../../helpers\");\n\nconst MODEL_MAP = {\n  \"gemini-embedding-001\": 2048,\n  \"gemini-embedding-2\": 8192,\n};\n\nclass GeminiEmbedder {\n  constructor() {\n    if (!process.env.GEMINI_EMBEDDING_API_KEY)\n      throw new Error(\"No Gemini API key was set.\");\n\n    this.className = \"GeminiEmbedder\";\n    const { OpenAI: OpenAIApi } = require(\"openai\");\n    this.model = process.env.EMBEDDING_MODEL_PREF || \"gemini-embedding-001\";\n    this.openai = new OpenAIApi({\n      apiKey: process.env.GEMINI_EMBEDDING_API_KEY,\n      // Even models that are v1 in gemini API can be used with v1beta/openai/ endpoint and nobody knows why.\n      baseURL: \"https://generativelanguage.googleapis.com/v1beta/openai/\",\n    });\n\n    this.maxConcurrentChunks = 4;\n\n    // https://ai.google.dev/gemini-api/docs/models/gemini#text-embedding-and-embedding\n    this.embeddingMaxChunkLength = MODEL_MAP[this.model] || 2_048;\n    this.log(\n      `Initialized with ${this.model} - Max Size: ${this.embeddingMaxChunkLength}` +\n        (this.outputDimensions\n          ? ` - Output Dimensions: ${this.outputDimensions}`","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/20f6d3546c1938bfea1ad304f58a592dddcc5948/server/utils/EmbeddingEngines/gemini/index.js#L1-L29","documentation":"Thrown by the GeminiEmbedder constructor when the GEMINI_EMBEDDING_API_KEY environment variable is empty or unset. AnythingLLM builds this class the moment the Gemini embedding engine is selected, so instantiation fails before any embedding request is made. The key is used against Google's OpenAI-compatible endpoint (https://generativelanguage.googleapis.com/v1beta/openai/), so it must be a Google AI Studio API key.","triggerScenarios":"Selecting Gemini as the embedding engine in system settings or setting EMBEDDING_ENGINE=gemini without defining GEMINI_EMBEDDING_API_KEY; starting the container without the variable in docker-compose/.env; a typo in the variable name (e.g. GEMINI_API_KEY) so the check sees nothing; .env edited after the process already started so the value was never loaded.","commonSituations":"Fresh installs where the admin configured the LLM provider but forgot the embedding provider key; Docker deployments missing the -e GEMINI_EMBEDDING_API_KEY flag; teams that copy .env.example and leave the embedding section commented out.","solutions":["Set GEMINI_EMBEDDING_API_KEY to a key created in Google AI Studio (https://aistudio.google.com/apikey)","If using Docker, add it to the environment block of docker-compose.yml (or pass -e) and recreate the container","Fully restart the server after editing .env so the new value is loaded","Confirm the exact spelling GEMINI_EMBEDDING_API_KEY (GEMINI_API_KEY is a different variable this class does not read)"],"exampleFix":"# before (env)\n# no embedding key set, EMBEDDING_ENGINE=gemini\n\n# after\nGEMINI_EMBEDDING_API_KEY=AIza...\nEMBEDDING_MODEL_PREF=gemini-embedding-001","handlingStrategy":"validation","validationCode":"function assertGeminiEmbedderConfigured() {\n  if (!process.env.GEMINI_EMBEDDING_API_KEY) {\n    throw new Error(\"Missing GEMINI_EMBEDDING_API_KEY — create one at https://aistudio.google.com/apikey\");\n  }\n}\nassertGeminiEmbedderConfigured();\nconst { GeminiEmbedder } = require(\"./server/utils/EmbeddingEngines/gemini\");\nconst embedder = new GeminiEmbedder();","typeGuard":null,"tryCatchPattern":"try {\n  const embedder = new GeminiEmbedder();\n} catch (e) {\n  if (e.message === \"No Gemini API key was set.\") {\n    // fail fast with an actionable config message; do not retry — construction is deterministic\n  }\n  throw e;\n}","preventionTips":["Add a startup config check that fails the process with a list of all missing embedding env vars instead of crashing on first use","Keep embedding credentials next to LLM credentials in the same .env so one review covers both","Run docker-compose config (or a printenv step in CI) to assert required variables exist before deploy"],"tags":["gemini","api-key","env-var","configuration","constructor"],"backgroundTag":"missing-api-key","analyzedSha":"20f6d3546c1938bfea1ad304f58a592dddcc5948","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}