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
- Set the key in System Settings -> AI Providers -> Anthropic (persists in storage) or export ANTHROPIC_API_KEY
- For Docker, pass -e ANTHROPIC_API_KEY=... or ensure the storage volume with saved provider settings is mounted
- Restart the server after setting the env var directly
- 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
- Persist provider credentials through the settings UI so they survive restarts
- Mount the storage volume in containerized deployments
- Health-check provider construction at startup rather than mid-chat
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
- No ApiPie LLM API key was set.
- No Azure API key was set.
- No Azure API endpoint was set.
- No Gemini API key was set.
- No Groq API key was set.
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)