Mintplex-Labs/anything-llm · error

No Anthropic API key was set.

Error message

No Anthropic API key was set.

What it means

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.

Solutions

  1. Set the key in System Settings -> AI Providers -> Anthropic (persists in storage) or export ANTHROPIC_API_KEY
  2. For Docker, pass -e ANTHROPIC_API_KEY=... or ensure the storage volume with saved provider settings is mounted
  3. Restart the server after setting the env var directly
  4. Sanity-check in the server context: Boolean(process.env.ANTHROPIC_API_KEY)

Example fix

# before
docker run -p 3001:3001 mintplexlabs/anythingllm

# after
docker run -p 3001:3001 -e ANTHROPIC_API_KEY=sk-ant-... -v anythingllm_storage:/app/storage mintplexlabs/anythingllm
Defensive patterns

Strategy: validation

Validate before calling

function canUseAnthropic() {
  return Boolean(process.env.ANTHROPIC_API_KEY);
}
if (!canUseAnthropic()) {
  return res.status(503).json({ error: "Anthropic provider is not configured" });
}
const llm = new AnthropicLLM(embedder, modelPref);

Try / catch

try {
  const llm = new AnthropicLLM(embedder, modelPref);
} catch (e) {
  if (/No Anthropic API key/i.test(e.message)) {
    return res.status(503).json({ error: "Set ANTHROPIC_API_KEY in provider settings" });
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@20f6d3546c (2026-08-18). Data as JSON: /api/errors/6f793c94a279a299. Report an issue: GitHub.

Appendix: source

Thrown at server/utils/AiProviders/anthropic/index.js:29

} = require("../../helpers/chat/LLMPerformanceMonitor");
const { getAnythingLLMUserAgent } = require("../../../endpoints/utils");

class AnthropicLLM {
  /**
   * List of Anthropic models that do not support the `temperature` inference parameter.
   * These models reject `temperature`/`top_p`/`top_k` with a 400 error.
   * @type {string[]}
   */
  noTemperatureModels = [
    "claude-opus-4-7",
    "claude-opus-4-8",
    "claude-sonnet-5",
    // Add other models here if identified
  ];

  constructor(embedder = null, modelPreference = null) {
    if (!process.env.ANTHROPIC_API_KEY)
      throw new Error("No Anthropic API key was set.");

    this.className = "AnthropicLLM";
    // Docs: https://www.npmjs.com/package/@anthropic-ai/sdk
    const AnthropicAI = require("@anthropic-ai/sdk");
    const anthropic = new AnthropicAI({
      apiKey: process.env.ANTHROPIC_API_KEY,
      defaultHeaders: {
        "User-Agent": getAnythingLLMUserAgent(),
      },
    });
    this.anthropic = anthropic;
    this.model =
      modelPreference ||
      process.env.ANTHROPIC_MODEL_PREF ||
      "claude-sonnet-4-6";
    this.limits = {
      history: this.promptWindowLimit() * 0.15,
      system: this.promptWindowLimit() * 0.15,

View on GitHub (pinned to 20f6d3546c)