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

  1. Read the console.error line directly above this throw - it contains the upstream Anthropic error
  2. Verify the key with a direct call to api.anthropic.com
  3. Re-select a currently supported Claude model in LLM preferences
  4. 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

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


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)