{"record":{"id":"f67fec47d3e74e17","repo":"Mintplex-Labs/anything-llm","slug":"gemini-api-key-must-be-provided-to-use-agents","errorCode":null,"errorMessage":"Gemini API key must be provided to use agents.","messagePattern":"Gemini API key must be provided to use agents\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/agents/index.js","lineNumber":241,"sourceCode":"          throw new Error(\"Z.AI API Key must be provided to use agents.\");\n        break;\n      case \"novita\":\n        if (!process.env.NOVITA_LLM_API_KEY)\n          throw new Error(\"Novita API Key must be provided to use agents.\");\n        break;\n      case \"nvidia-nim\":\n        if (!process.env.NVIDIA_NIM_LLM_BASE_PATH)\n          throw new Error(\n            \"NVIDIA NIM base path must be provided to use agents.\"\n          );\n        break;\n      case \"ppio\":\n        if (!process.env.PPIO_API_KEY)\n          throw new Error(\"PPIO API Key must be provided to use agents.\");\n        break;\n      case \"gemini\":\n        if (!process.env.GEMINI_API_KEY)\n          throw new Error(\"Gemini API key must be provided to use agents.\");\n        break;\n      case \"moonshotai\":\n        if (!process.env.MOONSHOT_AI_MODEL_PREF)\n          throw new Error(\"Moonshot AI model must be set to use agents.\");\n        break;\n      case \"cometapi\":\n        if (!process.env.COMETAPI_LLM_API_KEY)\n          throw new Error(\"CometAPI API Key must be provided to use agents.\");\n        break;\n      case \"foundry\":\n        if (!process.env.FOUNDRY_BASE_PATH)\n          throw new Error(\"Foundry base path must be provided to use agents.\");\n        break;\n      case \"giteeai\":\n        if (!process.env.GITEE_AI_API_KEY)\n          throw new Error(\"GiteeAI API Key must be provided to use agents.\");\n        break;\n      case \"cohere\":","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/agents/index.js#L223-L259","documentation":"Thrown by AgentHandler.checkSetup() (server/utils/agents/index.js:240) when the workspace agent provider is 'gemini' but GEMINI_API_KEY is unset/empty. Google Gemini (AI Studio / Generative Language API) authenticates with this single key, which is the only credential the guard validates.","triggerScenarios":"An agent invocation runs with workspace.agentProvider === 'gemini' while GEMINI_API_KEY is absent from process.env. Path: #providerSetupAndCheck() -> checkSetup() at index.js:476.","commonSituations":"Gemini selected in System > LLM Preference without a key; key from aistudio.google.com not pasted into .env; .env edited but the server not restarted; key revoked/regenerated in Google AI Studio.","solutions":["Create an API key at https://aistudio.google.com/app/apikey and set GEMINI_API_KEY in .env.","Restart AnythingLLM to reload process.env.","Validate with curl 'https://generativelanguage.googleapis.com/v1/models?key=$GEMINI_API_KEY'.","Confirm the agent model is a valid Gemini model id (e.g. gemini-1.5-pro)."],"exampleFix":"// before (.env)\n// GEMINI_API_KEY=\n\n// after (.env)\nGEMINI_API_KEY=AIza...your-key","handlingStrategy":"validation","validationCode":"const key = process.env.GEMINI_API_KEY;\nif (!key) {\n  throw new Error(\n    'Cannot start Gemini agent: set GEMINI_API_KEY (from aistudio.google.com/app/apikey) in .env.'\n  );\n}","typeGuard":null,"tryCatchPattern":"try {\n  await agentHandler.start();\n} catch (e) {\n  if (/Gemini API key must be provided/.test(e.message)) {\n    return respondConfigError('gemini', ['GEMINI_API_KEY']);\n  }\n  throw e;\n}","preventionTips":["Generate the key at aistudio.google.com and paste it into .env in one step.","Restart AnythingLLM to load the new env.","Add a CI/startup assertion that GEMINI_API_KEY is set when provider is gemini.","Keep .env out of version control; rotate keys in Google AI Studio on schedule."],"tags":["agents","llm-provider","gemini","google","api-key","environment-variables","config"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}