{"record":{"id":"bc1b62c517a911c7","repo":"Mintplex-Labs/anything-llm","slug":"openrouter-api-key-must-be-provided-to-use-agents","errorCode":null,"errorMessage":"OpenRouter API key must be provided to use agents.","messagePattern":"OpenRouter API key must be provided to use agents\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/agents/index.js","lineNumber":174,"sourceCode":"          throw new Error(\n            \"Azure OpenAI API endpoint and key must be provided to use agents.\"\n          );\n        break;\n      case \"koboldcpp\":\n        if (!process.env.KOBOLD_CPP_BASE_PATH)\n          throw new Error(\n            \"KoboldCPP must have a valid base path to use for the api.\"\n          );\n        break;\n      case \"localai\":\n        if (!process.env.LOCAL_AI_BASE_PATH)\n          throw new Error(\n            \"LocalAI must have a valid base path to use for the api.\"\n          );\n        break;\n      case \"openrouter\":\n        if (!process.env.OPENROUTER_API_KEY)\n          throw new Error(\"OpenRouter API key must be provided to use agents.\");\n        break;\n      case \"mistral\":\n        if (!process.env.MISTRAL_API_KEY)\n          throw new Error(\"Mistral API key must be provided to use agents.\");\n        break;\n      case \"generic-openai\":\n        if (!process.env.GENERIC_OPEN_AI_BASE_PATH)\n          throw new Error(\"API base path must be provided to use agents.\");\n        break;\n      case \"perplexity\":\n        if (!process.env.PERPLEXITY_API_KEY)\n          throw new Error(\"Perplexity API key must be provided to use agents.\");\n        break;\n      case \"textgenwebui\":\n        if (!process.env.TEXT_GEN_WEB_UI_BASE_PATH)\n          throw new Error(\n            \"TextWebGenUI API base path must be provided to use agents.\"\n          );","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/agents/index.js#L156-L192","documentation":"Thrown by AgentHandler.checkSetup() (server/utils/agents/index.js:173) when the workspace agent provider is 'openrouter' but OPENROUTER_API_KEY is unset/empty. OpenRouter is a hosted gateway to many models behind a single key, so AnythingLLM validates only that key. The guard fires before the agent session so an unauthenticated call never leaves the server.","triggerScenarios":"An agent invocation runs with workspace.agentProvider === 'openrouter' while OPENROUTER_API_KEY is absent from process.env. Path: #providerSetupAndCheck() -> checkSetup() at index.js:476.","commonSituations":"OpenRouter selected in System > LLM Preference without pasting a key; key revoked/deleted at openrouter.ai/keys but .env still holds the old (now empty) line; .env present but the Docker container was started without --env-file; trailing whitespace or quotes in the value stripped incorrectly.","solutions":["Create a key at https://openrouter.ai/keys and set OPENROUTER_API_KEY in .env.","Restart AnythingLLM so process.env reloads the key.","Confirm the key works with: curl -H 'Authorization: Bearer $OPENROUTER_API_KEY' https://openrouter.ai/api/v1/models.","Re-run the agent; the connection test in System > LLM Preference should now pass."],"exampleFix":"// before (.env)\n// OPENROUTER_API_KEY=\n\n// after (.env)\nOPENROUTER_API_KEY=sk-or-v1-...your-key","handlingStrategy":"validation","validationCode":"const key = process.env.OPENROUTER_API_KEY;\nif (!key || !key.startsWith('sk-or-')) {\n  throw new Error(\n    'Cannot start OpenRouter agent: set OPENROUTER_API_KEY (from openrouter.ai/keys) in .env.'\n  );\n}","typeGuard":null,"tryCatchPattern":"try {\n  await agentHandler.start();\n} catch (e) {\n  if (/OpenRouter API key must be provided/.test(e.message)) {\n    return respondConfigError('openrouter', ['OPENROUTER_API_KEY']);\n  }\n  throw e;\n}","preventionTips":["Store keys in a secret manager; load them into .env at deploy, never commit .env.","Restart AnythingLLM after updating OPENROUTER_API_KEY.","Add a CI check that asserts required env vars are non-empty for the configured provider.","Rotate keys at openrouter.ai/keys and update .env on the same host to avoid stale values."],"tags":["agents","llm-provider","openrouter","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"}