Claude API 401 Invalid x-api-key
Quick answer
A 401 authentication_error means the key is missing, mistyped or revoked. Check the key in the Console and how your app sends it.
Most likely fix: Verify the key
How to fix it
Try these in order — the most common fix is first.
1. Verify the key
- Open the Console API keys page and confirm the key is active
- Create a new key if unsure
Did this fix it?2. Check how it is sent
- Send it in the x-api-key header
- Check for stray quotes or newlines in env variables
Did this fix it?3. Look for stale values
- Search shell config and project .env files for an old ANTHROPIC_API_KEY
Did this fix it?
Symptoms
HTTP 401 authentication_error, 'invalid x-api-key'.
Why it happens
- Typo or whitespace in key
- Key revoked or deleted
- Wrong env variable or stale key in .env
This guide also covers
- claude api 401
- invalid x-api-key
Still not working?
If Anthropic Claude keeps failing, you're not alone. See every Anthropic Claude problem users report or the alternatives people switch to.
Have an app idea? Our small team builds any software: web and mobile apps, games, desktop, AI tools. Price agreed together.
Talk to us