OpenAI 429 and Anthropic 401 errors: check with curl

What OpenAI's 429 credit_balance_exhausted and Anthropic's 401 "invalid x-api-key" mean, how to tell the causes apart with one curl command, and how to fix each one.

Cent AIPublished 4 min read

Two errors stop a lot of AI projects: a 429 from OpenAI that says your credit is gone, and a 401 from Anthropic that says your key is invalid. Both look like "the API is broken", but each has a short list of causes. This post shows what each error means, how to find the cause with one curl command, and how to fix it.

OpenAI 429 credit_balance_exhausted

OpenAI's error code guide lists "429 - Credit balance exhausted" with the code credit_balance_exhausted. The cause it gives is "Your organization has no prepaid credits remaining", and the fix is "Add credits to continue using the API" (source). The same page notes that the broader error.type can still be insufficient_quota, so older code that checks only the type keeps working.

This 429 is not a rate limit. Waiting and retrying does not help, because no request is accepted until the organization has credit again. Two things to check:

  • The right organization. Credit belongs to an organization. A key created in another organization, or in a project of one without credit, gets the 429 even when your main organization has credit.
  • The balance itself. Open the billing page of the organization and check that the credit is above zero.

Anthropic 401 invalid x-api-key

Anthropic's error reference lists "401 - authentication_error: There's an issue with your API key" (source). We sent a request with a made-up key on 2026-11-14 and got this body back:

{"type":"error","error":{"type":"authentication_error","message":"invalid x-api-key"},"request_id":"req_<redacted>"}

The usual causes:

  • The key was cut off or has spaces. A key copied from a chat or a document often picks up a space, a line break or a missing last character.
  • The environment variable is not set in this shell. export in one terminal does not reach another terminal, an IDE or a service.
  • The wrong key for the endpoint. An OpenAI key sent to Anthropic, or a key from another gateway, always gets a 401.
  • The key was revoked in the Console, or belongs to a workspace that was archived.

Anthropic also has a separate "402 - billing_error: There's an issue with your billing or payment information" (source). A 401 is about the key; a 402 is about billing.

Find the cause with curl

Run one request outside your app. If it works with curl and fails in your app, the problem is in how the app reads the key, not in the key.

For OpenAI:

curl https://api.openai.com/v1/models \
  -H "Authorization: Bearer $OPENAI_API_KEY"

For Anthropic:

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":"YOUR_MODEL","max_tokens":16,"messages":[{"role":"user","content":"hi"}]}'

Before blaming the key, check that the shell really has it: echo ${#OPENAI_API_KEY} prints its length, and 0 means the variable is empty.

What curl returnsLikely causeFix
401, Incorrect API key provided (OpenAI)Key mistyped, cut off or revokedCopy the key again, without spaces, or create a new one
401, invalid x-api-key (Anthropic)Key mistyped, cut off, revoked, or not an Anthropic keyCopy the key again from the Console, check the variable name
429, credit_balance_exhausted (OpenAI)The organization has no prepaid creditAdd credit to the organization that owns the key
402, billing_error (Anthropic)Billing or payment informationFix billing in the Console
curl works, the app failsThe app reads another variable, a stale .env, or another base URLPrint the key length and base URL inside the app

If you pay with a balance on Cent AI

Cent AI serves both formats: OpenAI at https://api.cent-ai.dev/v1 and Anthropic Messages at https://api.cent-ai.dev. The same key works in Authorization: Bearer and in x-api-key. Errors come back in the format of the endpoint you call, so the checks above still apply. A wrong key gives:

{"error":{"code":"invalid_api_key","message":"Invalid API key. Check the key or create a new one in the dashboard.","param":null,"type":"authentication_error"}}

The codes you are most likely to see:

CodeHTTPMeaning
invalid_api_key401The key is wrong, revoked, or belongs to a blocked account
insufficient_balance402No balance available for this model
model_not_found404The model name is not in the model list
rate_limited429Over 600 requests per minute on this key
key_limit_exceeded429The key reached the daily or monthly limit you set

Every response has an x-request-id header, and the same ID is on the Requests page of the dashboard. A request rejected before it reaches a model is not charged. The full list is in Errors.

The balance is prepaid: you top up with QRIS in rupiah, or with USDT or USDC on Solana (network fees charged by your wallet are yours). Every payment is manual, with no card on file and no auto-renewal, so a 402 means the balance is empty, not that a card failed.

Sources

  1. developers.openai.com/api/docs/guides/error-codes (opens in a new tab) · accessed 2026-11-14
  2. platform.claude.com/docs/en/api/errors (opens in a new tab) · accessed 2026-11-14
  3. cent-ai.dev/docs/reference/errors (opens in a new tab) · accessed 2026-11-14
  4. cent-ai.dev/docs/reference/errors/4xx (opens in a new tab) · accessed 2026-11-14
ShareXThreads