AI · 2026-11-25 · 9 min

Claude Code 429, 529 and 401 Retry Guide

How to tell a Claude Code 429 rate limit from a 529 overload and a 401 credential failure, with safe retry rules, backoff and jitter, and Retry-After.

By Open Error Codes EditorialReviewed 2026-11-25

Claude Code prints the API status alongside most runtime failures, and three codes drive nearly every retry decision. 429 is a quota you can wait out, 529 is capacity you cannot control, and 401 is a credential problem that waiting never fixes. Retry policy follows from that split, not from a blanket retry-on-failure loop.

Match the code to the cause

Claude Code calls the Claude API for every model response, so the terminal error usually carries the status even when the wording is local. The Claude Code error reference maps each status to a recovery step, and the API documents the same codes for direct HTTP clients. Ask one question before you write a retry loop: is the failure about volume, capacity, or identity? Volume and capacity improve with time. Identity does not.

429: a quota window, not a broken client

A 429 with the type rate_limit_error means the request exceeded a limit attached to the organization: requests per minute, input tokens per minute, output tokens per minute, or an acceleration limit triggered by ramping traffic up quickly. The request was valid. Nothing about your code or machine is wrong, and a new key inherits the same limit.

Most throttles include retry-after, which is the authoritative wait. The exception is a spend-cap 429: same type, no retry-after, and a detail such as enforced_spend_limit_reached. Retrying it fails until the cycle resets or the tier changes, and SDK retries cannot clear a budget.

529: capacity you do not control

A 529 carries overloaded_error and means the API is under heavy load across customers, not just you. The request was well formed; the service declined to serve it now. Because the cause is shared, a 529 says nothing about your configuration and usually clears on its own. Back off with jitter, cap the attempts, and check the Anthropic status page if it persists.

401: a credential problem that waiting cannot fix

A 401 means authentication failed: the credential is missing, empty, malformed, revoked, or not accepted by the workspace or gateway you are calling. Claude Code reports invalid authentication credentials, and its reference also covers local variants such as an unresolvable method, a failing apiKeyHelper script, an organization that has disabled API key authentication, and a signed-out session.

None of those is transient, and retrying the same credential produces the same rejection. The one legitimate retry is a refresh: Claude Code re-runs an apiKeyHelper on a 401 or 403 and retries with its fresh output. Without a helper, fix the source first.

What is safe to retry

Retry only when a later attempt can plausibly succeed and a duplicate cannot cause damage.

  • Safe: 429 throttles with retry-after, after waiting the stated interval.
  • Safe: 529 overloads, with backoff, jitter, and a hard attempt cap.
  • Safe with care: 5xx, timeouts, and dropped connections that arrive before any response content, and only for read-only or idempotent work.
  • Not safe: 401 and 403 until a credential or policy changes.
  • Not safe: 400, 404, and 422, which stay wrong on retry.
  • Not safe: a 429 without retry-after that looks like a spend cap.
  • Not safe: failures after text streamed or a tool call ran, where a replay can repeat side effects.

That last rule is why Claude Code does not re-run a request when a server error lands mid-stream after a tool call: it keeps the completed output and continues from the finished calls. Copy the instinct. Retry the request, not the effects.

Exponential backoff with jitter

Doubling delays alone are not enough. Workers that fail together stay synchronized and collide again, so spread the attempts out:

delay = random_uniform(0, min(cap, base * 2 ** attempt))
# base = 0.5s, cap = 30s, 5 to 6 attempts

Cap total wall-clock time as well as the attempt count, because a long stream can sit between attempts. Claude Code retries transient failures up to ten times with exponential backoff, and exposes the overload delay floor and ceiling as environment variables.

Read Retry-After before you invent a delay

retry-after is either an integer number of seconds or an HTTP date. Parse both, clamp the result to a maximum you can tolerate, and log the raw value so a later reader can tell a one-second throttle from a ten-minute one. Absent on a 429, treat it as a budget signal rather than an invitation to guess. On a 529 the header is optional: honour it when present, fall back to backoff when it is not.

When not to rotate keys

Rotation is an identity operation, so it only helps when identity is the problem. A 429 or 529 is not. Swapping the key mid-incident invalidates it for every other job in that environment, sends each one through a 401 of its own, and hides the real fault. A fresh key is also easier to overuse, because nobody has tuned its concurrency.

Rotate when a key is revoked, exposed, or scoped to the wrong workspace. If several tools share one key, reduce their combined concurrency first; for more throughput, raise the tier instead of minting a second key.

Check the key, the workspace, and the environment

A 401 is usually plumbing, not a typo. Confirm which credential source is actually in play, and mask it while you look:

env | grep ANTHROPIC | sed 's/=.*/=<redacted>/'
# ANTHROPIC_API_KEY=<set, redacted>
# ANTHROPIC_BASE_URL=<unset>

An empty variable, an assignment that was never exported, a different value in a container or CI secret, and a variable set in another shell all produce the same 401 with different fixes. Claude Code can authenticate through an environment key, an interactive login, an apiKeyHelper, a cloud credential, or a gateway named by ANTHROPIC_BASE_URL; check the one your process would pick. Behind a gateway, the 401 may not come from Anthropic at all.

Then confirm the workspace: a revoked key, a key from another workspace, disabled API key auth, and an exhausted spend limit all reject a well-formed credential. Record the CLI version before comparing behaviour with documentation:

claude --version

CLI and CI behaviour

Interactively, Claude Code shows a retry countdown with the attempt number and reason, and reports the error only after its budget is spent. In CI that patience looks like a hang. CLAUDE_CODE_MAX_RETRIES defaults to 10 and is capped at 15; lowering it surfaces failures sooner. For unattended runs, CLAUDE_CODE_RETRY_WATCHDOG=1 keeps retrying 429 and 529 capacity errors past the cap, with a maximum-wait variable bounding each request.

CI adds two failure modes. Parallel runners sharing one key synchronize their retries and manufacture 429s that never appear locally, so stagger starts and lower concurrency before touching retry counts. And a secret present in the pipeline but absent from your debugging shell looks exactly like a revoked key. Log status, request ID, and delay for every failed attempt.

The three codes side by side

Keep this next to the retry loop. The deciding column is not the status but the signal.

StatusWhat it meansSafe to retry?Decided byFirst action
429A per-minute request or token limit was exceededYes, after a waitretry-after presentWait the stated interval
429 spend capThe budget for the cycle is exhaustedNoNo retry-after, spend-cap detailEscalate; do not loop
529The API is overloaded across all customersYes, boundedBackoff budget and status pageBack off, cut concurrency
401Credential missing, invalid, revoked, or not acceptedNoA credential or config changeFix the active source
403Credential understood but not permittedNoPolicy or workspace changeCheck policy

A decision path

  1. Read the code, not the sentence. 401 and 403 leave the retry path; 429 and 529 enter it.
  2. On a 429, look for retry-after. Present means wait that long. Absent means a budget issue, so stop.
  3. On a 529, check the status page, back off with jitter, lower concurrency, and give up after a fixed count.
  4. On a 401, find the source the process uses, correct it, and retry once by hand. Do not loop.
  5. If a bounded retry still fails, escalate with status, headers, command, timestamp, and CLI version.

Inspect the response with curl

Confirm what the endpoint returns from the machine that fails. The key below is a placeholder; never commit it.

curl -sS -i 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": "<model-id>", "max_tokens": 16,
       "messages": [{"role": "user", "content": "ping"}]}'

The status line and retry-after are what matter, so keep the headers and drop the body when scripting the check:

curl -sS -o /dev/null -D - --max-time 30 \
  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 @request.json | grep -iE '^(HTTP/|retry-after|request-id)'

If the same request returns 401 in one shell and succeeds in another, the environment differs, not the credential. A consistent 429 means the limit is real and the fix is volume or tier.

A retry loop you can bound

This skips SDK retries so the behaviour is explicit. In production, let the SDK retry first and apply this to what it hands back.

attempt = 0
while attempt < MAX_ATTEMPTS:                 # 5 is a reasonable start
    response = post_message()
    if response.status in (401, 403):
        raise Fatal(response)                 # fix credentials, do not retry
    if response.status not in (429, 529) and response.status < 500:
        return response
    wait = parse_retry_after(response)        # seconds or HTTP date
    if wait is None:
        if response.status == 429:
            raise BudgetExhausted(response)   # spend cap: stop now
        wait = random_uniform(0, min(CAP, BASE * 2 ** attempt))
    sleep(wait)
    attempt += 1
raise GiveUpWithRequestId(response)

Sources

Search the code you are seeing

Every page links the official source and the date it was last checked.

Search codes