entry
No. 22
date
filed under
debugging, agents
checked against
6 sources

Claude API 529 overloaded_error: Retries and Model Fallbacks

A Claude API 529 with overloaded_error means the API is temporarily overloaded, not that your request is wrong or that you hit your own rate limit. The body looks like {"type": "error", "error": {"type": "overloaded_error", "message": "Overloaded"}}. Anthropic's error docs say a 529 "can occur when the API experiences high traffic across all users." The fix is on your side of the call: retry with backoff, and in an agent loop, fall back to a second model when the first one stays overloaded. The official SDKs already retry a 529 twice, so the error you see is what is left after those retries.

This post covers what the Python SDK does with a 529 by default, how to give it more room, a small fallback wrapper for agent loops, and the case the SDK never retries: an overload that arrives in the middle of a stream. The SDK behavior below was checked by reading the source of the anthropic Python package, version 2.14.0, and by running it on Python 3.13 against a fake HTTP transport that returns 529s. No request was sent to the real API.

529 is not 429

The two errors look alike and call for different fixes. From the Claude API error reference:

  • 429 rate_limit_error: your organization hit a rate limit, its monthly spend cap or a Claude Code workspace spend limit. The fix is in your usage or your limits. The docs warn that a spend-cap 429 "has no retry-after header and keeps failing until access resumes," so retry 429s only a few times.
  • 529 overloaded_error: the API itself is under load. Nothing about your request or your account caused it, and waiting or switching models can help.
  • 500 api_error: an unexpected internal error. The docs say to retry only if the x-should-retry header isn't false.

Every response carries a request-id header, and error bodies repeat it as request_id. Log it with every failure. If a 529 lasts, check the Claude status page before you change any code, and include request IDs if you contact support.

What the SDK does with a 529 by default

The errors page says the SDK "retries a failed request up to two times (three attempts in all)." It retries connection errors, timeouts and the statuses 408, 409, 429 and 500 and above, so 529 is covered. If the response has an x-should-retry header, the SDK follows it instead. If it has a retry-after header, the SDK waits that long. Otherwise it uses "exponential backoff from 0.5 to 8 seconds."

The Python source shows the details. _constants.py sets DEFAULT_MAX_RETRIES = 2, INITIAL_RETRY_DELAY = 0.5 and MAX_RETRY_DELAY = 8.0. _calculate_retry_timeout doubles the delay on each retry up to the cap and multiplies it by a random factor between 0.75 and 1.0. With the defaults, that is roughly half a second and then one second of waiting before the SDK gives up.

Against a fake transport that returned 529 every time, a default client made 3 attempts and raised anthropic.OverloadedError after 1.41 seconds. A real overload often lasts longer than that.

In Python, a 529 raises OverloadedError, which is a subclass of InternalServerError. The docs note that "a 503 with overloaded_error counts as a 5xx, not as a 529," and in the test a 503 with that body raised ServiceUnavailableError, not OverloadedError. If you want to catch every overload, check the error's type, not only its class.

Give the retries more room

The simplest change is a higher retry count. Set it on the client, or for one call with with_options:

import anthropic

client = anthropic.Anthropic(max_retries=5)

# Or only for one call:
message = client.with_options(max_retries=5).messages.create(
    model="claude-opus-5-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Summarize the ticket."}],
)

With max_retries=5 the SDK waits up to about 0.5, 1, 2, 4 and 8 seconds between attempts, 15.5 seconds in all at most. In the test, a client with max_retries=5 against a transport that failed 3 times succeeded on the 4th attempt after 3.23 seconds, and with_options(max_retries=4) made 5 attempts. max_retries=0 turns retries off and made exactly 1 attempt.

That is enough for a user-facing request that can wait a few seconds. An agent that runs for minutes has a better option than waiting: another model.

Fall back to another model in an agent loop

An agent loop calls the model once per turn, and a 529 on turn 12 can throw away the work of the first 11. Retrying the same overloaded model is one choice. Sending that one turn to a second model is often faster, the same idea as sending easy turns to a cheaper model in LLM model routing.

This wrapper tries each model in order. If all of them are overloaded, it waits with full jitter and tries the list again. Anything that isn't an overload is raised at once:

import random
import time

import anthropic


def is_overloaded(err: Exception) -> bool:
    """True for a 529, a 503 overloaded_error, or an overloaded_error event in a stream."""
    return isinstance(err, anthropic.APIStatusError) and (
        err.status_code == 529 or err.type == "overloaded_error"
    )


def create_with_fallback(client, models, max_rounds=3, base_delay=2.0, max_delay=30.0, **kwargs):
    """Try each model in order. If all are overloaded, wait and try the list again."""
    last_err = None
    for round_no in range(max_rounds):
        for model in models:
            try:
                return client.messages.create(model=model, **kwargs)
            except anthropic.APIStatusError as err:
                if not is_overloaded(err):
                    raise  # 400s, auth errors, spend caps: retrying won't help
                last_err = err
        if round_no < max_rounds - 1:
            # Full jitter: a random wait between 0 and the capped exponential delay.
            time.sleep(random.uniform(0, min(max_delay, base_delay * 2**round_no)))
    raise last_err

Use it in place of client.messages.create for each turn:

client = anthropic.Anthropic(max_retries=1)
MODELS = ["claude-opus-5-5", "claude-sonnet-5-5"]

response = create_with_fallback(
    client, MODELS, max_tokens=4096, tools=tools, messages=messages
)

Results from the fake transport:

A answered by claude-sonnet-5-5 calls: ['claude-opus-5-5', 'claude-opus-5-5', 'claude-sonnet-5-5']
B gave up after 6 calls, 0.25s
C BadRequestError raised at once
D 503: ServiceUnavailableError False True
E stream: APIStatusError 200 overloaded_error True requests: 1

In A, the first model always returned 529. The SDK retried it once, because the client had max_retries=1, and the wrapper then moved to the second model. In B, both models were overloaded and the SDK's retries were off, so the wrapper made 3 rounds of 2 calls and raised the last OverloadedError. C shows a 400 going straight through. D is a 503 overload: not an OverloadedError, but is_overloaded catches it. E is a stream, covered below.

A few choices here are deliberate:

  • Retry at one layer. The wrapper and the SDK both retry. Keep the SDK's count low (0 or 1) so they don't multiply. The reasons are in agent tool retries: stacked retries add load to a service that is already struggling.
  • Retry the model call, not the turn. Wrap only the messages.create call. Tools that already ran on this turn must not run again because the next model call failed.
  • Keep the history valid for every model. Each tool_use block in the history still needs its tool_result in the next user message, whichever model answers. If a fallback breaks that pairing, you get the error in tool_use ids without tool_result blocks.
  • Choose fallbacks that can do the job. Send the same tools, system prompt and settings, and run your evals on the fallback model too. Use the model IDs from Anthropic's models overview or the List Models endpoint, not ones you remember.
  • Cap the total. max_rounds and max_delay bound how long one turn can wait. Without a cap, an outage becomes an agent run that never ends, which is the same failure as an agent infinite loop.

A 529 in the middle of a stream

Streaming changes the error. Once the API has returned 200 and started the stream, an overload arrives as an event:

event: error
data: {"type": "error", "error": {"type": "overloaded_error", "message": "Overloaded"}}

The streaming docs say this "would normally correspond to an HTTP 529 in a non-streaming context." The errors page is clear on the consequence: "The SDK doesn't retry an error in a stream." In Python, the error reaches your code as APIStatusError, and its status is the stream's 200 or missing, so a branch for OverloadedError won't catch it. Check e.type == "overloaded_error" instead, as Anthropic's handle-errors page does. In the test (E above), the SDK raised APIStatusError with status_code 200 and type overloaded_error, after a single request.

You then have two options. Anthropic's streaming docs describe recovery: save what arrived, then send a new request that continues it. For Claude 4.6 and later models, that means a user message that contains the partial response and asks the model to continue. The docs also warn that tool_use and thinking blocks "cannot be partially recovered."

In an agent loop, the turn often ends in a tool_use block, so the simpler choice is to discard the partial response and run the whole turn again through the same fallback logic. Apply is_overloaded to errors from the stream and retry the turn as a whole. Don't run any tool calls from a stream that didn't finish.

Log enough to see the pattern

Each 529 is a data point. Record the model, the attempt number, whether a fallback answered and the request_id on the error. In traces, as in agent observability tracing, put them on the model call's span. If most of your fallbacks happen at the same hour or on the same model, that tells you when to schedule batch work or which model to try first.

Checklist

  • Tell 529 (API overloaded) apart from 429 (your limits) and 400 (your request).
  • Know the default: 2 SDK retries, about 1.5 seconds of waiting in all.
  • Raise max_retries for calls that can wait, or use with_options per call.
  • In agent loops, fall back to a second model after the first stays overloaded.
  • Retry at one layer: keep SDK retries low when your wrapper also retries.
  • Catch overloads by type == "overloaded_error" too, for 503s and streams.
  • Never re-run tools because a model call failed.
  • Cap total wait time per turn.
  • Log request_id, and check the status page when 529s persist.

FAQ

What does Claude API error 529 overloaded_error mean?

The API is temporarily overloaded. Anthropic's docs say it can occur "when the API experiences high traffic across all users." It doesn't mean your request is invalid or that you hit your own rate limit.

Does the Anthropic SDK retry 529 errors?

Yes. By default it retries twice, three attempts in all, with exponential backoff from 0.5 to 8 seconds, or the wait in a retry-after header if the response has one. Set max_retries on the client to change the count. Errors inside a stream are not retried.

What is the difference between 429 and 529 on the Claude API?

A 429 rate_limit_error is about your organization: a rate limit or spend cap. A 529 overloaded_error is about the API's load across all users. A spend-cap 429 keeps failing until access resumes; a 529 can clear on the next try.

How do I catch an overloaded error in a Claude stream?

Catch anthropic.APIStatusError and check e.type == "overloaded_error". The stream already returned 200, so OverloadedError won't match.

Should I switch models when Claude is overloaded?

In a long agent run, falling back to a second model for one turn is often better than waiting. Keep the same tools and history, test the fallback with your evals, and cap the total wait.

Sources

  • Anthropic, Claude API errors (documentation: HTTP errors, retries, error shapes, SDK error types, request IDs)
  • Anthropic, Handle errors (documentation: catching errors by kind, errors in a stream)
  • Anthropic, Streaming messages (documentation: error events, error recovery)
  • Anthropic, Models overview (documentation: current model IDs, List Models endpoint)
  • Anthropic, anthropic-sdk-python (SDK source, version 2.14.0: _constants.py, _base_client.py)
  • Anthropic, Claude status (status page)

Stuck on a different message? The error index lists every agent error covered here, by tool.

Next in the notebook

  1. No. 2AI Agent Calling the Wrong Tool? 7 Causes and How to Fix Them

    A debugging checklist for tool-calling agents: overlapping tools, vague descriptions, ambiguous parameters, noisy output and bad errors, with a fix for each.

  2. No. 7Agent Infinite Loop: How to Debug Agents That Never Stop

    Why AI agents get stuck in infinite loops, and how to stop them: turn caps, token budgets, repeated-call detection, better tool errors and clear stop rules.

  3. No. 11Agent Observability Tracing: What to Log on Every Step

    Trace an AI agent with OpenTelemetry: one span per run, model call and tool call, which gen_ai attributes to record, and how to keep prompts out of traces.