{"record":{"id":"01cacab46a8b5d79","repo":"Mintplex-Labs/anything-llm","slug":"no-gemini-api-key-was-set","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/AiProviders/gemini/index.js","lineNumber":30,"sourceCode":"const { defaultGeminiModels, v1BetaModels } = require(\"./defaultModels\");\nconst { safeJsonParse } = require(\"../../http\");\nconst cacheFolder = path.resolve(\n  process.env.STORAGE_DIR\n    ? path.resolve(process.env.STORAGE_DIR, \"models\", \"gemini\")\n    : path.resolve(__dirname, `../../../storage/models/gemini`)\n);\n\nconst NO_SYSTEM_PROMPT_MODELS = [\n  \"gemma-3-1b-it\",\n  \"gemma-3-4b-it\",\n  \"gemma-3-12b-it\",\n  \"gemma-3-27b-it\",\n];\n\nclass GeminiLLM {\n  constructor(embedder = null, modelPreference = null) {\n    if (!process.env.GEMINI_API_KEY)\n      throw new Error(\"No Gemini API key was set.\");\n\n    this.className = \"GeminiLLM\";\n    const { OpenAI: OpenAIApi } = require(\"openai\");\n    this.model =\n      modelPreference ||\n      process.env.GEMINI_LLM_MODEL_PREF ||\n      \"gemini-2.0-flash-lite\";\n\n    const isExperimental = this.isExperimentalModel(this.model);\n    this.openai = new OpenAIApi({\n      apiKey: process.env.GEMINI_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.limits = {\n      history: this.promptWindowLimit() * 0.15,\n      system: this.promptWindowLimit() * 0.15,","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/gemini/index.js#L12-L48","documentation":"Thrown by the GeminiLLM constructor when process.env.GEMINI_API_KEY is unset. Gemini is reached through Google's OpenAI-compatible endpoint (v1beta/openai/), which still requires the Gemini API key as the bearer token. Without it the OpenAI client cannot authenticate and the provider refuses to construct.","triggerScenarios":"Constructing `new GeminiLLM(embedder, modelPreference)` while GEMINI_API_KEY is absent from process.env — fires at provider selection when the user chose Gemini but supplied no key.","commonSituations":".env missing the GEMINI_API_KEY line; key revoked or never created in Google AI Studio; key stored in a different env source not loaded by AnythingLLM; Docker deployment without the env passthrough.","solutions":["Create a key at Google AI Studio (aistudio.google.com) and put GEMINI_API_KEY=... in .env","Restart AnythingLLM so process.env picks up the new key","Confirm the key works with a direct curl to the Gemini OpenAI endpoint before configuring AnythingLLM","If running in Docker, pass -e GEMINI_API_KEY or use an env file"],"exampleFix":"// before\n// .env: (no GEMINI vars beyond maybe a model pref)\n\n// after\n// .env:\n//   GEMINI_API_KEY=AIzaSy...\n//   GEMINI_LLM_MODEL_PREF=gemini-2.0-flash-lite","handlingStrategy":"validation","validationCode":"function hasGeminiKey() {\n  return Boolean(process.env.GEMINI_API_KEY);\n}\nif (!hasGeminiKey()) {\n  throw new ConfigError('Create a key in Google AI Studio and set GEMINI_API_KEY.');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate the key with a cheap /models call at startup","Store secrets via a secrets manager rather than raw .env in production","Surface missing-key as a UI banner, not a runtime crash"],"tags":["gemini","configuration","authentication","environment-variables","constructor"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}