What does Anthropic '401 authentication_error' mean?
The Claude API couldn't authenticate the x-api-key header. The key is missing, malformed, disabled, deleted or expired. Create a new key in the Claude Console, set it as a server-side env var (ANTHROPIC_API_KEY), and redeploy. If the old key was ever in frontend code or a public repo, treat it as leaked.
Last updated 2026-11-25 · Reviewed by ProofForge
The exact error
{"type":"error","error":{"type":"authentication_error","message":"invalid x-api-key"}}Why it happens
- Env var not set in production, or set with extra quotes or whitespace.
- Key disabled, deleted or expired in the Console.
- Sending the key as
Authorization: Bearerinstead of thex-api-keyheader when calling the HTTP API directly.
How to fix it
- Create a new key in the Claude Console's API keys page.
- Set
ANTHROPIC_API_KEYon the server and call the API from your backend. - If calling over HTTP, send
x-api-keyandanthropic-versionheaders.
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{"model":"<model>","max_tokens":64,"messages":[{"role":"user","content":"ping"}]}'Check it's fixed
One server call returns 200. Your built frontend JS contains no sk-ant- string.
Check your live app
A free, read-only public-surface scan. It cannot diagnose private sessions or every cause described above.
FAQ
Can I call the Claude API from the browser?
Not with a standard API key. Anyone could copy it from your JavaScript. Proxy through your server.
Disable or delete a leaked key?
Disable stops it immediately and is reversible. Delete it once you've confirmed nothing depends on it.
Why 401 and not 403?
401 means the key itself wasn't accepted. 403 (permission_error) means the key works but lacks access to that resource.