{"record":{"id":"6f793c94a279a299","repo":"Mintplex-Labs/anything-llm","slug":"no-anthropic-api-key-was-set","errorCode":null,"errorMessage":"No Anthropic API key was set.","messagePattern":"No Anthropic API key was set\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/anthropic/index.js","lineNumber":29,"sourceCode":"} = require(\"../../helpers/chat/LLMPerformanceMonitor\");\nconst { getAnythingLLMUserAgent } = require(\"../../../endpoints/utils\");\n\nclass AnthropicLLM {\n  /**\n   * List of Anthropic models that do not support the `temperature` inference parameter.\n   * These models reject `temperature`/`top_p`/`top_k` with a 400 error.\n   * @type {string[]}\n   */\n  noTemperatureModels = [\n    \"claude-opus-4-7\",\n    \"claude-opus-4-8\",\n    \"claude-sonnet-5\",\n    // Add other models here if identified\n  ];\n\n  constructor(embedder = null, modelPreference = null) {\n    if (!process.env.ANTHROPIC_API_KEY)\n      throw new Error(\"No Anthropic API key was set.\");\n\n    this.className = \"AnthropicLLM\";\n    // Docs: https://www.npmjs.com/package/@anthropic-ai/sdk\n    const AnthropicAI = require(\"@anthropic-ai/sdk\");\n    const anthropic = new AnthropicAI({\n      apiKey: process.env.ANTHROPIC_API_KEY,\n      defaultHeaders: {\n        \"User-Agent\": getAnythingLLMUserAgent(),\n      },\n    });\n    this.anthropic = anthropic;\n    this.model =\n      modelPreference ||\n      process.env.ANTHROPIC_MODEL_PREF ||\n      \"claude-sonnet-4-6\";\n    this.limits = {\n      history: this.promptWindowLimit() * 0.15,\n      system: this.promptWindowLimit() * 0.15,","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/20f6d3546c1938bfea1ad304f58a592dddcc5948/server/utils/AiProviders/anthropic/index.js#L11-L47","documentation":"The AnthropicLLM constructor throws immediately when process.env.ANTHROPIC_API_KEY is unset, before the SDK client is built. AnythingLLM manages provider credentials at runtime (saved through the AI provider settings UI into storage), so selecting Anthropic without ever saving a key - or losing the storage/env between restarts - produces this on the first chat completion. The error propagates out of provider construction into the chat handler.","triggerScenarios":"Choosing Anthropic as the workspace LLM provider without entering a key; running docker/podman without -e ANTHROPIC_API_KEY and without the persisted storage volume; env vars set in an interactive shell but the server started by a service manager that drops them.","commonSituations":"Container recreated without env or volume; .env file not loaded in production; the key configured only on a dev machine; multi-instance deployments where one node lacks the env.","solutions":["Set the key in System Settings -> AI Providers -> Anthropic (persists in storage) or export ANTHROPIC_API_KEY","For Docker, pass -e ANTHROPIC_API_KEY=... or ensure the storage volume with saved provider settings is mounted","Restart the server after setting the env var directly","Sanity-check in the server context: Boolean(process.env.ANTHROPIC_API_KEY)"],"exampleFix":"# before\ndocker run -p 3001:3001 mintplexlabs/anythingllm\n\n# after\ndocker run -p 3001:3001 -e ANTHROPIC_API_KEY=sk-ant-... -v anythingllm_storage:/app/storage mintplexlabs/anythingllm","handlingStrategy":"validation","validationCode":"function canUseAnthropic() {\n  return Boolean(process.env.ANTHROPIC_API_KEY);\n}\nif (!canUseAnthropic()) {\n  return res.status(503).json({ error: \"Anthropic provider is not configured\" });\n}\nconst llm = new AnthropicLLM(embedder, modelPref);","typeGuard":null,"tryCatchPattern":"try {\n  const llm = new AnthropicLLM(embedder, modelPref);\n} catch (e) {\n  if (/No Anthropic API key/i.test(e.message)) {\n    return res.status(503).json({ error: \"Set ANTHROPIC_API_KEY in provider settings\" });\n  }\n  throw e;\n}","preventionTips":["Persist provider credentials through the settings UI so they survive restarts","Mount the storage volume in containerized deployments","Health-check provider construction at startup rather than mid-chat"],"tags":["anthropic","api-key","environment","configuration"],"backgroundTag":"missing-env-var","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"}