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-key header 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

  1. Read the JSON. Anthropic says every error has a top-level error object with type and message, plus a request_id. A 401 is authentication_error. A 402 is billing_error.
  2. For a 401, confirm the server sends header x-api-key with the key from ANTHROPIC_API_KEY on 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.
  3. If that key was leaked or revoked, create a new key in the Claude Console, put it only on the server, and redeploy.
  4. 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.
  5. 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 type is gone. If it is still billing_error, the Console payment details are still the open item.
  • The browser bundle does not contain the key.

Sources

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.

See products