Claude Code API Error Codes: 400 to 529 Fixed

Claude Code API error codes explained: what 400, 401, 402, 404, 429, 500, 503 and 529 mean, the exact messages, and tested one-line fixes for each.

GoiAPI · · 18 min read

Ask AI and more
View as Markdown

Terminal showing Claude Code API errors for 401, an unreachable server and a model issue, next to tiles for codes 401, 402, 404, 429, 503 and DNS

A Claude Code API error tells you two things: an HTTP status code and a message, and together they almost always name the cause. 401 means the key is wrong or missing, 402 means your balance is too low, 404 means a wrong model name or a wrong base URL path, 429 means too many requests or an overloaded model, and 500, 503 or 529 are temporary server-side problems. Errors with no status code at all, such as ENOTFOUND or an SSL certificate failure, mean the request never reached the server.

This guide covers each code as you see it when Claude Code runs with your own API key and a custom ANTHROPIC_BASE_URL, with messages we reproduced in Claude Code 2.1.325 and the fix for each.

Disclosure: GoiAPI sells API access to the models mentioned in this article.

Claude Code API error codes at a glance

CodeWhat it meansFirst thing to try
400The request is invalid, most often because the conversation is over the context window/compact or /clear
401The API key is missing, mistyped or revokedCheck which key Claude Code is sending with /status
402Not enough balance to cover the requestTop up, or lower max_tokens
403The key is valid but not allowed to use this model or this IPCheck the key's restrictions
404Wrong model name, or wrong path (often /v1 added to the base URL)Fix the base URL first, then the model name
429Too many requests per minute, too many at once, a spending limit, or an overloaded modelWait for Retry-After, reduce parallel subagents
500Internal server errorRetry; send the request ID if it repeats
503Maintenance, or the model is temporarily not respondingRetry in a few minutes
529Anthropic's API is overloadedWait, or switch model with /model
No codeDNS, proxy, firewall or certificate problemRun the curl check below

The rest of the article goes code by code. If you already know your code, jump to its section.

How to read a Claude Code API error

Claude Code prints API failures in a fixed shape: API Error:, then the status code, then the message the API sent back. For any 5xx response, Claude Code shows the status code and the API's error message, and when ANTHROPIC_BASE_URL points at a custom host, the trailing hint names that host instead of Anthropic's status page (Claude Code error reference, checked on December 5, 2026).

Before showing you anything, Claude Code has usually retried already. Per the same reference, it retries transient failures up to 10 times with exponential backoff: server errors, overloaded responses, timeouts, dropped connections and temporary 429 throttles. It does not retry a certificate validation failure, and it does not retry a spending-limit 429 marked x-should-retry: false. So when an error reaches your screen, retrying by hand right away rarely helps; fix the cause first.

When you use GoiAPI as the endpoint, every response also carries an x-request-id header, and 500 errors, 503 errors caused by a model not responding, and some 400 errors end with "Support ID: …" in the message. Send that ID to support and the request can be looked up directly. The full list of gateway messages is on the GoiAPI error codes page.

8 Claude Code API errors we reproduced

We ran claude -p "hi" --max-turns 1 with a separate config directory and a fake key (sk-test-...), changing one setting at a time. The runs were on Claude Code 2.1.325 on Windows 10, on December 3, 2026; we re-ran rows 4, 5 and 6 on December 5, 2026 with the same version and got the same output.

#SetupWhat Claude Code printed
1ANTHROPIC_BASE_URL=https://api.goiapi.com, wrong keyFailed to authenticate. API Error: 401 followed by the gateway's message, which is in your account's language; in English it reads The API key is invalid or has been revoked.
2Same as 1, key in ANTHROPIC_AUTH_TOKEN instead of ANTHROPIC_API_KEYSame as 1. GoiAPI accepts the key in either header.
3Base URL with a trailing slash: https://api.goiapi.com/Same as 1. The trailing slash does no harm.
4Base URL with /v1: https://api.goiapi.com/v1There's an issue with the selected model (claude-opus-5-5). It may not exist or you may not have access to it. Run --model to pick a different model.
5http:// instead of https://Same as 4
6Base URL set, no key at allNot logged in · Please run /login
7ANTHROPIC_MODEL set to a model that does not exist, wrong keyA warning that Claude Code doesn't recognize the model, then the same 401 as row 1
8Misspelled domain: https://api.goiapi.cmAbout 3 minutes of silence while Claude Code retried, then API Error: Can't reach the API server — check your internet or DNS (ENOTFOUND)

Three things from this table save the most time:

  • "There's an issue with the selected model" does not always mean the model is wrong. In row 4, Claude Code appends /v1/messages to the base URL, so the request goes to /v1/v1/messages. The gateway answers 404 with The path POST /v1/v1/messages does not exist. (we checked with curl on December 5, 2026), and Claude Code reports it as a model problem. In row 5, http://api.goiapi.com answers with a 301 redirect (same curl check), and the result is identical. If you are sure the model name is right, check the base URL first.
  • A wrong model name can still show up as 401, because the key is checked before the model. Fix the key, and the model error appears next.
  • A wrong domain takes minutes to fail, because Claude Code retries network errors before giving up.

400: invalid request or prompt too long

A 400 means the request itself was rejected. With Claude Code, the usual cause is a conversation plus attached files that no longer fits the model's context window. Claude Code shows this as Prompt is too long; in an interactive session the line reads Context limit reached · /compact or /clear to continue (Claude Code error reference, checked on December 5, 2026).

Fix: type /compact to summarize the conversation and keep going, or /clear if you don't need the earlier context. For big files, point Claude at the file path instead of pasting the contents. More causes and fixes: Claude Code Prompt is too long.

Through GoiAPI, when the model rejects the request content, a non-streaming request gets the original status code and error, and a streaming request gets an invalid_request_error event inside the stream (Streaming docs). Other 400 messages from the gateway are about a malformed request, for example The maximum number of output tokens is too large.

401: invalid or missing API key

401 means the key was not recognized: it is mistyped, has a stray space or line break, was revoked, or Claude Code is sending an old key you forgot about. The two GoiAPI messages are:

  • Missing API key. Send your key in the Authorization: Bearer <key> header or the x-api-key header.
  • The API key is invalid or has been revoked.

If you see Not logged in · Please run /login after setting a base URL, Claude Code found no key at all (row 6 above).

Fix:

  1. Run /status inside Claude Code to see which credential it is actually using.
  2. In the same shell, list what is set: env | grep ANTHROPIC on macOS or Linux, Get-ChildItem Env:ANTHROPIC* in PowerShell. The Claude Code reference notes that direnv, dotenv plugins and IDE terminals can load a stale key from a .env file without you noticing.
  3. Remove the old value, set the right one, and start Claude Code from a new terminal.

The step-by-step cleanup for Windows, macOS and VS Code is in Claude Code invalid API key: causes and fixes. Which headers GoiAPI accepts is on the authentication page.

402: balance too low

Before calling the model, GoiAPI holds an estimated amount from your balance. The hold is based on the estimated input tokens and the max_tokens value of the request. When the request finishes, only the actual usage is charged and the rest of the hold is released (Limits and balance). If your balance can't cover the hold, you get 402:

Your balance is too low for this request (about ${amount} needs to be held). Please top up your balance.

The amount in the message is the hold, not the real cost of the request. We have not reproduced this error inside Claude Code.

Fix: top up your balance, or set a lower max_tokens when the balance is low so the hold is smaller. Per-token prices for each model are on the pricing page. Top-ups are final and non-refundable, so add only what you plan to use. If a card is what stops you from topping up, you can pay for the Claude API with USDT, no credit card.

On Anthropic's own API, the equivalent situation shows in Claude Code as Credit balance is too low, and Anthropic documents 402 as billing_error, a problem with billing or payment information (Anthropic API errors, checked on December 5, 2026).

403: key not allowed for this model or IP

403 is different from 401: the key is valid but restricted. The GoiAPI messages are This API key is not allowed to use the model {model}. and This API key cannot be used from IP address {ip}.

Fix: open the key's settings in the dashboard and add the model or your current IP to its allowed list, or use a key without those restrictions.

404: model not found or wrong path

There are two kinds of 404 from GoiAPI:

  • The model {model} does not exist. See the list at /v1/models. The model name is wrong. Model names are case-sensitive and use hyphens, for example claude-opus-5-5 and claude-haiku-5-5. The current list is on the Models page and through the /v1/models endpoint.
  • The path {method} {path} does not exist. The URL is wrong. With Claude Code this nearly always means /v1 was added to ANTHROPIC_BASE_URL.

As the reproduction table shows, Claude Code often reports both cases the same way: There's an issue with the selected model. Check in this order:

  1. ANTHROPIC_BASE_URL is exactly https://api.goiapi.com, with https and no /v1.
  2. The model name matches the list exactly.
  3. No stale model is set somewhere else, such as ANTHROPIC_MODEL in your shell or the env block of ~/.claude/settings.json.

If you are pointing Claude Code at a non-Claude model, see Claude Code Router: use GPT, DeepSeek and GLM models.

429: rate limit, concurrency, spending limit or overload

A 429 from GoiAPI has four possible causes, and the message tells you which:

CauseMessage
Too many requests per minute for the keyThis API key has reached its limit of {limit} requests per minute. Please try again in {seconds} s.
Too many requests running at once on the accountYour account already has {max} requests running at the same time. Please wait for one to finish, then try again.
A daily spending limit you set on the keyRequest rejected because it would exceed the daily spending limit of this API key (${limit}). The key works again from {reopenAt}, or you can raise the limit on the API Keys page.
The model is overloadedThe model is overloaded. Please try again in a few minutes.

Some details that help:

  • Per-minute limit. Non-streaming responses carry x-ratelimit-limit-requests, x-ratelimit-remaining-requests and x-ratelimit-reset-requests headers. Our test key showed x-ratelimit-limit-requests: 60 on December 3, 2026; other keys can differ. The Retry-After header says how many seconds to wait.
  • Concurrency. This is the one Claude Code users hit when many subagents run in parallel. Fewer parallel subagents, or waiting for one to finish, clears it.
  • Spending limits come with x-should-retry: false, so Claude Code does not keep retrying a request that can't succeed until the limit resets. Raise the limit on the API Keys page if you need to keep going.
  • Overload. Claude Code retries temporary 429s on its own before showing the error.

On Anthropic's API, Claude Code shows a rate limit as API Error: Request rejected (429) · this may be a temporary capacity issue..., and the reference suggests checking /status for a stray ANTHROPIC_API_KEY and reducing parallel subagents (checked on December 5, 2026).

500 and 503: server errors

A 500 is an unexpected internal error. It is not caused by your prompt or settings. GoiAPI's message is Something went wrong on our side. Please try again later. Support ID: {requestId}.

A 503 means maintenance (The service is under maintenance. Please try again in a few minutes.) or a model that is temporarily not responding (The model is temporarily not responding. Please try again later. Support ID: {requestId}). Maintenance responses include Retry-After: 60.

Fix: wait a minute and send again. Your message is still in the conversation, so typing try again is enough. If it keeps failing, check the status page and send the support ID. If a proxy or load balancer in between returns its own HTML error page, Claude Code shows the status code and the page title, such as API Error: 502 Bad Gateway.

A failed request that returns no content is not charged, unless you cancel it yourself (error codes docs).

529: overloaded

529 is the code Anthropic's API uses when it is at capacity. Claude Code retries several times before printing:

API Error: Repeated 529 Overloaded errors. The API is at capacity — this is usually temporary. Try again in a moment. If it persists, check https://status.claude.com.

According to the Claude Code reference, a 529 is not your usage limit and doesn't count against your quota, and since capacity is tracked per model, switching with /model lets you keep working (checked on December 5, 2026).

GoiAPI never returns 529. An overloaded model returns 429 (type rate_limit_error in the Anthropic format), and a model that is temporarily not responding returns 503 (type overloaded_error). During a streamed answer, the error arrives as an error event in the stream. Claude Code retries both. Retry counts, backoff settings and switching models are covered in Claude 529 overloaded error: what it means and fixes.

Unable to connect to API: DNS, proxy and SSL errors

Connection errors have no HTTP code, because the request never reached a server. These are the forms listed in the Claude Code error reference (checked on December 5, 2026):

MessageWhat it usually means
Can't reach the API server — check your internet or DNS (ENOTFOUND)The domain doesn't resolve: a typo in the base URL, DNS or VPN trouble
Connection refused — a firewall or proxy may be blocking it (ConnectionRefused)A firewall or proxy blocks the connection, or the base URL points at a local proxy that isn't running
Connection dropped (ECONNRESET)The connection was cut partway
Couldn't connect through your proxy (ERR_PROXY_TUNNEL) — the proxy refused the tunnel: check its credentials and that it allows this hostThe proxy refused to open the connection
Unable to connect to API: SSL certificate verification failed (UNABLE_TO_GET_ISSUER_CERT_LOCALLY)...A corporate proxy or security tool re-signs HTTPS traffic with its own certificate
API Error: Connection lost mid-response. The response above may be incomplete.The connection dropped while the answer was streaming

Is it your network or the service?

Run this from the same terminal you start Claude Code in. It needs no key:

BASH
curl -i https://api.goiapi.com/v1/models

On PowerShell, type curl.exe instead of curl. An HTTP 401 with the message Missing API key... means your network reaches GoiAPI fine (we ran it on December 5, 2026). If curl works but Claude Code still fails, check that ANTHROPIC_BASE_URL isn't set to different values in your shell and in the env block of settings.json.

Proxy settings

Claude Code reads the standard HTTPS_PROXY, HTTP_PROXY and NO_PROXY variables and does not support SOCKS proxies (Claude Code network configuration, checked on December 5, 2026). The example from that page:

BASH
export HTTPS_PROXY=https://proxy.example.com:8080

Set it before launching Claude Code, then run /status and check the Proxy row.

SSL certificate errors

Claude Code trusts both its bundled certificates and your operating system's certificate store, so installing your company's root certificate in the OS store is often enough. Otherwise, point Claude Code at the certificate file (from the same page):

BASH
export NODE_EXTRA_CA_CERTS=/path/to/ca-cert.pem

Do not set NODE_TLS_REJECT_UNAUTHORIZED=0. The Claude Code reference warns against it because it turns off certificate validation entirely. Certificate failures are not retried, so this error shows up on the first attempt.

Timeouts: API_TIMEOUT_MS and Bash command timeouts

Two different timeouts get mixed up:

  • API_TIMEOUT_MS is how long each API request attempt waits to receive its response headers. The default is 600000 ms (10 minutes), and it doesn't limit how long a streaming response runs after that (Claude Code environment variables, checked on December 5, 2026). Raise it on slow networks or behind a proxy. With GoiAPI, streaming requests get their 200 headers right away, and a : ping line is sent every 15 seconds while the model hasn't sent anything, so the connection stays open. Each request can run for up to 15 minutes.
  • BASH_DEFAULT_TIMEOUT_MS and BASH_MAX_TIMEOUT_MS control commands Claude Code runs on your machine, such as builds and tests. The defaults are 120000 ms (2 minutes) and 600000 ms (10 minutes) (same source). If a long build gets cut off, raise these, not API_TIMEOUT_MS.

Put them in the env block of ~/.claude/settings.json:

JSON
{
  "env": {
    "API_TIMEOUT_MS": "900000",
    "BASH_DEFAULT_TIMEOUT_MS": "300000",
    "BASH_MAX_TIMEOUT_MS": "1200000"
  }
}

The full setup for your key, base URL and settings file on Windows, macOS and VS Code is in Claude Code API key setup.

Subscription login or your own API key?

If you have a Claude Pro, Max or other plan with usage left, signing in with your claude.ai account avoids the whole group of base URL and key errors. If your plan has run out, see Claude Code usage limit reached for when it resets and how to keep working. Note that as of v2.1.196, Remote Control is disabled when ANTHROPIC_BASE_URL points at a host other than api.anthropic.com (environment variables, checked on December 5, 2026). Your own API key makes sense when you want to pay per token, pay with crypto instead of a card, or use one key for several models. For a cost comparison, see Claude Code Max vs API.

One thing to watch when you switch back and forth: a leftover ANTHROPIC_API_KEY in your environment takes requests away from your subscription. Run /status to see which credential is active.

FAQ

What does "API Error" mean in Claude Code?

It means the request to the model API failed. The number after API Error: is the HTTP status code and the text after it is the API's own message. Claude Code has usually retried several times before showing it.

Why does Claude Code say there's an issue with the selected model when the model name is correct?

Almost always the base URL is wrong: it ends in /v1 or uses http://. Set ANTHROPIC_BASE_URL=https://api.goiapi.com and run again. If it still fails, compare the name with the model list.

How do I fix "Unable to connect to API" in Claude Code?

Check the spelling of ANTHROPIC_BASE_URL, run the curl check above from the same terminal, then look at your proxy, VPN and firewall. If curl works, look for a different ANTHROPIC_BASE_URL value in settings.json.

What is ECONNRESET in Claude Code?

The connection was closed partway, by the server or by a proxy, VPN or firewall in between. Claude Code retries it automatically. If it keeps happening, try without the VPN or on another network.

How do I increase the timeout in Claude Code?

For slow API responses, raise API_TIMEOUT_MS. For Bash commands that get cut off, raise BASH_DEFAULT_TIMEOUT_MS and BASH_MAX_TIMEOUT_MS. Both go in the env block of ~/.claude/settings.json.

Am I charged for failed requests?

On GoiAPI, a failed request that returns no content is not charged, except a request you cancel yourself. If you cancel after the request has reached the model but before any content arrives, you pay for the input tokens or the minimum charge, whichever is higher (streaming docs).

Does a 529 error use up my Claude usage limit?

No. The Claude Code reference states that a 529 is not your usage limit and doesn't count against your quota.

Get started with GoiAPI in Claude Code

  1. Create a GoiAPI account and create an API key in the dashboard.
  2. Top up with USDT (TRC20 or BEP20) or Binance Pay. No credit card and no monthly fee. Top-ups are final and non-refundable, so add only what you expect to use.
  3. Set ANTHROPIC_BASE_URL=https://api.goiapi.com (no /v1) and ANTHROPIC_AUTH_TOKEN=sk-..., pick a model such as claude-haiku-5-5, and run claude.

The Claude Code integration guide has the exact commands for macOS, Linux and PowerShell, and the quickstart covers your first test call. For any error not listed here, check the error codes reference and keep the x-request-id handy when you contact support.

Related posts