Mintplex-Labs/anything-llm · error
AnthropicLLM::getChatCompletion failed to communicate with…
Error message
AnthropicLLM::getChatCompletion failed to communicate with Anthropic. ${error.message} What it means
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.
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
Example fix
// before
const result = await anthropic.getChatCompletion(messages);
// after
let result;
for (let attempt = 1; attempt <= 3; attempt++) {
try {
result = await anthropic.getChatCompletion(messages);
break;
} catch (e) {
if (/rate limit|overloaded/i.test(e.message) && attempt < 3) {
await new Promise((r) => setTimeout(r, 2 ** attempt * 1000));
} else throw e;
}
} Defensive patterns
Strategy: try-catch
Try / catch
try {
const response = await llm.getChatCompletion(messages);
} catch (e) {
if (/failed to communicate with Anthropic/i.test(e.message)) {
const m = e.message;
if (/401|authentication/i.test(m)) handleBadKey();
else if (/429|rate limit|529|overloaded/i.test(m)) return retryWithBackoff(fn);
else if (/404|model/i.test(m)) handleBadModel();
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- e.message
- Mistral Failed to embed
- An error occurred while deleting the model
- ApiPie chat: is not valid for chat completion!
- Bad Request
AI-assisted analysis of Mintplex-Labs/anything-llm@20f6d3546c (2026-08-18).
Data as JSON: /api/errors/364bd2b9dcd9ebd4.
Report an issue: GitHub.
Appendix: source
Thrown at server/utils/AiProviders/anthropic/index.js:255
const promptTokens = result.output.usage.input_tokens;
const completionTokens = result.output.usage.output_tokens;
return {
textResponse: result.output.content[0].text,
metrics: {
prompt_tokens: promptTokens,
completion_tokens: completionTokens,
total_tokens: promptTokens + completionTokens,
outputTps: completionTokens / result.duration,
duration: result.duration,
model: this.model,
provider: this.className,
timestamp: new Date(),
},
};
} catch (error) {
console.error(error);
throw new Error(
`AnthropicLLM::getChatCompletion failed to communicate with Anthropic. ${error.message}`
);
}
}
async streamGetChatCompletion(messages = null, { temperature = 0.7 }) {
await this.assertModelMaxTokens();
const systemContent = messages[0].content;
const measuredStreamRequest = await LLMPerformanceMonitor.measureStream({
func: this.anthropic.messages.stream({
model: this.model,
max_tokens: this.maxTokens,
system: this.#buildSystemPrompt(systemContent),
messages: messages.slice(1), // Pop off the system message
temperature: this.temperatureParam(temperature),
}),
messages,
runPromptTokenCalculation: false,View on GitHub (pinned to 20f6d3546c)