# What does Anthropic '401 authentication_error' mean?

**Short answer:** 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

```text
{"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: Bearer` instead of the `x-api-key` header when calling the HTTP API directly.

## How to fix it

1. Create a new key in the Claude Console's API keys page.
2. Set `ANTHROPIC_API_KEY` on the server and call the API from your backend.
3. If calling over HTTP, send `x-api-key` and `anthropic-version` headers.

```bash
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.

> **Scan box (use the site's ScanBox component):** Check whether your live app has this problem. Paste your URL for a free outside-in scan covering exposed keys, open database rules, CORS and security headers. [Scan my app free →](https://proofforge.live/#scan)

## 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.

## Sources

- [Anthropic: API errors](https://docs.anthropic.com/en/api/errors)
- [Anthropic: API key best practices](https://support.anthropic.com/en/articles/9767949-api-key-best-practices-keeping-your-keys-safe-and-secure)

## Related

- [Anthropic (Claude) key leaked: first 10 minutes](/leaked-keys/anthropic)
- [Fix: Anthropic key exposed](/fix/anthropic-key-exposed)
- [Exposed API key checker](/tools/exposed-api-key-checker)
- [All errors](/errors)
