Anthropic API 401 authentication_error or 402 billing_error
Claude returns 401 authentication_error or 402 billing_error in production? The x-api-key is bad, or billing in the Claude Console needs a look. Anthropic's errors page does not use the phrase credit balance is too low.
Reviewed October 18, 2026
What it means in plain English
Anthropic's errors page splits these two responses. HTTP 401 with type authentication_error means there is an issue with the API key: it is malformed, revoked, or expired. On Claude Platform on AWS, the same status can mean the AWS credentials or the SigV4 signature. HTTP 402 with type billing_error means there is an issue with billing or payment information. Check the Claude Console, or AWS Marketplace if you use Claude Platform on AWS.
The current errors page does not use the sentence "credit balance is too low", and it does not use the sentence "invalid x-api-key". Match the type field. A 400 invalid_request_error can also mean you hit a spend limit you set, except a Claude Code workspace limit, which can be a 429. A 429 rate_limit_error is a rate limit or a spend cap, not a bad key.
Likely causes
- Production is still sending the key from your laptop, or the host variable is empty, so the
x-api-keyheader is wrong. - The key was revoked or expired, and the deploy was not updated.
- The key is in the browser bundle. Anyone can copy it. See Anthropic API key in the front-end code.
- Billing or the payment method in the Claude Console is the problem, which is the 402, not the 401.
How to fix it, step by step
- Read the JSON. Anthropic says every error has a top-level
errorobject withtypeandmessage, plus arequest_id. A 401 isauthentication_error. A 402 isbilling_error. - For a 401, confirm the server sends header
x-api-keywith the key fromANTHROPIC_API_KEYon the host. Anthropic's own example uses that header and that variable name. Redeploy after you change the value. Keep that key on the server. See Anthropic API key in the front-end code. - If that key was leaked or revoked, create a new key in the Claude Console, put it only on the server, and redeploy.
- For a 402, open the Claude Console and check the payment details. On AWS, check the Marketplace subscription. Anthropic says that is the check for
billing_error. - Do not treat a 429 as a bad key. That page is Anthropic or Gemini API 429 and overloaded errors.
How to check it worked
- The same request returns a model response.
- The error
typeis gone. If it is stillbilling_error, the Console payment details are still the open item. - The browser bundle does not contain the key.
Sources
Related fixes
More AI API errors fixes
Keep going on your own.
The guides stay free. A deep leak report is $15. Fix packs are $24, or $49 for all three. There is no done-for-you repair.