Mintplex-Labs/anything-llm · critical · Error
No Anthropic API key was set.
Error message
No Anthropic API key was set.
What it means
Thrown by the AnthropicLLM constructor when process.env.ANTHROPIC_API_KEY is falsy at instantiation time. The provider refuses to construct because every downstream call (chat, stream, embed) needs a valid key. It is a hard precondition gate, not a retryable network failure.
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 526360e320)
Solutions
- Add `ANTHROPIC_API_KEY=sk-ant-...` to the server's .env file and restart the AnythingLLM process/container so dotenv reloads.
- In the UI, re-open System > LLM Provider and confirm the key field is saved; AnythingLLM writes provider keys to .env on save.
- Verify the variable is actually exported in the running process: `node -e "console.log(Boolean(process.env.ANTHROPIC_API_KEY))"` from the same shell/container.
- Check for typos or trailing whitespace in the key name and value; an empty or quoted-empty string still fails the truthiness check.
Example fix
// before // .env ANTHROPIC_API_KEY= // after // .env ANTHROPIC_API_KEY=sk-ant-api03-xxxxxxxxxxxxxxxxxxxxxxxx
Defensive patterns
Strategy: validation
Validate before calling
// Before constructing AnthropicLLM
if (!process.env.ANTHROPIC_API_KEY) {
throw new Error(
"ANTHROPIC_API_KEY is missing. Set it in .env or the provider UI before selecting Anthropic."
);
}
const llm = new AnthropicLLM(embedder, modelPref); Type guard
/**
* @param {unknown} v
* @returns {boolean} v is a non-empty api key string
*/
function isNonEmptyKey(v) {
return typeof v === "string" && v.trim().length > 0;
}
isNonEmptyKey(process.env.ANTHROPIC_API_KEY); Try / catch
// Construction-time guards are not retryable; catch only to surface a friendly message.
try {
const llm = new AnthropicLLM(embedder, modelPref);
} catch (e) {
if (/No Anthropic API key/.test(e.message)) {
return { ok: false, reason: "config", message: "Set ANTHROPIC_API_KEY." };
}
throw e;
} Prevention
- Validate required provider env vars at app boot and fail with a consolidated error before serving traffic.
- Use a single source of truth for provider config (AnythingLLM's provider settings) rather than ad-hoc .env edits.
- Add a smoke-test endpoint that constructs the selected provider on save and reports success/failure.
- Document each provider's required env var names in onboarding so users don't mistype them.
When it happens
Trigger: Instantiating `new AnthropicLLM(embedder, model)` (e.g. when a user picks the Anthropic provider in system setup or sends the first chat message) while ANTHROPIC_API_KEY is unset, empty string, or whitespace. AnythingLLM loads providers lazily, so this typically fires on the first request after selecting Anthropic, not at server boot.
Common situations: Fresh install where .env was never populated; .env edited but server not restarted; key put under a wrong name (ANTHROPIC_API_KEY vs ANTHROPIC_KEY); Docker container missing the -e flag or env_file; copied .env.example to .env but left the value blank.
Related errors
- No ApiPie LLM API key was set.
- No Azure API key was set.
- AWS_BEDROCK_LLM_API_KEY is required for AWS Bedrock.
- No Cerebras API key was set.
- No Cohere API key was set.
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/6f793c94a279a299.
Report an issue: GitHub.