Skip to main content
401Not retryable

Anthropic 401 Authentication Error

The x-api-key header is missing, malformed, revoked, or belongs to a disabled workspace.

Most likely causes

  1. 1.ANTHROPIC_API_KEY env var unset in the deploy environment
  2. 2.Key sent as Authorization: Bearer instead of the x-api-key header
  3. 3.Key rotated/revoked in the console but still cached in your secrets store
  4. 4.anthropic-version header missing on raw HTTP calls

Fix checklist

  • Confirm the key prefix is sk-ant- and it loads at runtime (log its length, never its value)
  • Use header x-api-key, plus anthropic-version: 2023-06-01 on raw fetch calls
  • Generate a fresh key in console.anthropic.com and rotate your secret
  • Check the key's workspace wasn't disabled for billing

Retry guidance

Never retry 401s — repeated auth failures can trip abuse detection. Fix credentials.

// 401 is NOT retryable — surface it and fix the request/config.
const res = await fetch("https://api.anthropic.com/v1/messages", {
  method: "POST",
  headers: {
    "content-type": "application/json",
    "x-api-key": process.env.ANTHROPIC_API_KEY!,
      "anthropic-version": "2023-06-01",
  },
  body: JSON.stringify(payload),
});
if (res.status === 401) {
  const body = await res.json();
  // Do not retry: log the provider's message — it names the exact problem.
  throw new Error(`Anthropic 401: ${JSON.stringify(body.error ?? body)}`);
}

Provider status page: status.anthropic.com