{"record":{"id":"364bd2b9dcd9ebd4","repo":"Mintplex-Labs/anything-llm","slug":"anthropicllm-getchatcompletion-failed-to-communic","errorCode":null,"errorMessage":"AnthropicLLM::getChatCompletion failed to communicate with Anthropic. ${error.message}","messagePattern":"AnthropicLLM::getChatCompletion failed to communicate with Anthropic\\. (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/anthropic/index.js","lineNumber":255,"sourceCode":"      const promptTokens = result.output.usage.input_tokens;\n      const completionTokens = result.output.usage.output_tokens;\n\n      return {\n        textResponse: result.output.content[0].text,\n        metrics: {\n          prompt_tokens: promptTokens,\n          completion_tokens: completionTokens,\n          total_tokens: promptTokens + completionTokens,\n          outputTps: completionTokens / result.duration,\n          duration: result.duration,\n          model: this.model,\n          provider: this.className,\n          timestamp: new Date(),\n        },\n      };\n    } catch (error) {\n      console.error(error);\n      throw new Error(\n        `AnthropicLLM::getChatCompletion failed to communicate with Anthropic. ${error.message}`\n      );\n    }\n  }\n\n  async streamGetChatCompletion(messages = null, { temperature = 0.7 }) {\n    await this.assertModelMaxTokens();\n    const systemContent = messages[0].content;\n    const measuredStreamRequest = await LLMPerformanceMonitor.measureStream({\n      func: this.anthropic.messages.stream({\n        model: this.model,\n        max_tokens: this.maxTokens,\n        system: this.#buildSystemPrompt(systemContent),\n        messages: messages.slice(1), // Pop off the system message\n        temperature: this.temperatureParam(temperature),\n      }),\n      messages,\n      runPromptTokenCalculation: false,","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/20f6d3546c1938bfea1ad304f58a592dddcc5948/server/utils/AiProviders/anthropic/index.js#L237-L273","documentation":"Wraps every failure from the Anthropic messages call inside getChatCompletion: HTTP errors (401 invalid key, 404 unknown model, 429 rate limit, 529 overloaded), network errors, or SDK timeouts. The original error is console.error'd immediately before the re-throw, so the server log holds the unwrapped cause one line up. The wrapper names the provider class and method so the failing hop is identifiable in aggregated logs.","triggerScenarios":"Expired or revoked ANTHROPIC_API_KEY; model preference pointing at a retired Claude model; sustained multi-user traffic hitting org rate limits; egress-blocked networks that cannot reach api.anthropic.com; prompt + max_tokens exceeding the model's context.","commonSituations":"Key rotated outside the app; Claude model names deprecated by Anthropic; corporate proxies requiring an allowlist; bursty workspaces with no backoff; noTemperatureModels mismatches producing upstream 400s.","solutions":["Read the console.error line directly above this throw - it contains the upstream Anthropic error","Verify the key with a direct call to api.anthropic.com","Re-select a currently supported Claude model in LLM preferences","Retry with exponential backoff on 429/529 and allowlist api.anthropic.com on proxies"],"exampleFix":"// before\nconst result = await anthropic.getChatCompletion(messages);\n\n// after\nlet result;\nfor (let attempt = 1; attempt <= 3; attempt++) {\n  try {\n    result = await anthropic.getChatCompletion(messages);\n    break;\n  } catch (e) {\n    if (/rate limit|overloaded/i.test(e.message) && attempt < 3) {\n      await new Promise((r) => setTimeout(r, 2 ** attempt * 1000));\n    } else throw e;\n  }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const response = await llm.getChatCompletion(messages);\n} catch (e) {\n  if (/failed to communicate with Anthropic/i.test(e.message)) {\n    const m = e.message;\n    if (/401|authentication/i.test(m)) handleBadKey();\n    else if (/429|rate limit|529|overloaded/i.test(m)) return retryWithBackoff(fn);\n    else if (/404|model/i.test(m)) handleBadModel();\n  }\n  throw e;\n}","preventionTips":["Alert on the unwrapped cause logged just above the throw, not only the wrapper message","Keep Claude model preferences current with the supported catalog","Wrap calls in exponential backoff for 429/529","Allowlist api.anthropic.com in egress filters and proxies"],"tags":["anthropic","api","network","chat-completion"],"backgroundTag":"llm-api-request-failed","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"}