{"record":{"id":"0fb08cec9236e454","repo":"Mintplex-Labs/anything-llm","slug":"openai-api-key-must-be-provided-to-use-agents","errorCode":null,"errorMessage":"OpenAI API key must be provided to use agents.","messagePattern":"OpenAI API key must be provided to use agents\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/agents/index.js","lineNumber":132,"sourceCode":"            from: WORKSPACE_AGENT.name,\n            to: USER_AGENT.name,\n            content: response?.text || \"\",\n            state: \"success\",\n          }\n        );\n      });\n      return agentHistory;\n    } catch (e) {\n      this.log(\"Error loading chat history\", e.message);\n      return [];\n    }\n  }\n\n  checkSetup() {\n    switch (this.provider) {\n      case \"openai\":\n        if (!process.env.OPEN_AI_KEY)\n          throw new Error(\"OpenAI API key must be provided to use agents.\");\n        break;\n      case \"anthropic\":\n        if (!process.env.ANTHROPIC_API_KEY)\n          throw new Error(\"Anthropic API key must be provided to use agents.\");\n        break;\n      case \"lmstudio\":\n        if (!process.env.LMSTUDIO_BASE_PATH)\n          throw new Error(\"LMStudio base path must be provided to use agents.\");\n        break;\n      case \"ollama\":\n        if (!process.env.OLLAMA_BASE_PATH)\n          throw new Error(\"Ollama base path must be provided to use agents.\");\n        break;\n      case \"groq\":\n        if (!process.env.GROQ_API_KEY)\n          throw new Error(\"Groq API key must be provided to use agents.\");\n        break;\n      case \"togetherai\":","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/20f6d3546c1938bfea1ad304f58a592dddcc5948/server/utils/agents/index.js#L114-L150","documentation":"Setup guard in checkSetup(): the agent framework was configured with provider 'openai' but the OPEN_AI_KEY environment variable is unset, so no API client can be constructed. It is a fail-fast configuration sentinel, not a runtime API failure — the credential must be present before any agent session starts.","triggerScenarios":"OpenAI was selected as the agent provider but no API key is configured.","commonSituations":"This error is raised at runtime in server/utils/agents/index.js. It occurs when the required configuration for this provider is missing or invalid (unset environment variables, empty API key or base path), when the external service is unreachable or returns an unexpected response, or when invalid input reaches the call site. To prevent it, validate the relevant provider settings and environment variables at startup and confirm the service is reachable before this code path executes.","solutions":["Set the OPEN_AI_KEY environment variable.","Or select a different agent provider in the workspace settings."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}