Python SDK Retry and Timeout Configuration Reference
This page inferred a generic reference-list layout: it groups the anthropic Python SDK's retry and timeout settings by where they're configured, so you can look up the right knob without re-reading the whole SDK reference.
Every setting shown applies identically to Anthropic() and AsyncAnthropic() unless noted otherwise.
Start with the Client-level defaults group if you're setting policy for your whole application.
Use the Per-request overrides group when one specific call needs different behavior than the client's default.
The What gets retried table tells you which failures the SDK handles automatically, so you don't build redundant retry logic on top of it.
Revisit this page whenever you add a new call site with unusual latency or reliability requirements (a long-running agent loop, a user-facing request with a tight SLA, and so on).
Use with_options(...) to override a setting for a single call without changing the client's defaults.
# One call needs a tighter timeout and no retries - a latency-sensitive UI requestresponse = client.with_options( max_retries=0, timeout=5.0,).messages.create( model="claude-sonnet-5", max_tokens=200, messages=[{"role": "user", "content": "Quick classification: is this spam? ..."}],)
Call shape
Effect
client.with_options(max_retries=N)
Overrides retry count for calls made on the returned object; the original client is unchanged.
client.with_options(timeout=N)
Overrides the per-attempt timeout the same way.
client.with_options(max_retries=N, timeout=N)
Both overrides can be combined in a single call.
with_options(...) returns a new client-like object; it does not mutate the original client, so the pattern is safe to use inline per call without affecting other code paths sharing the same client.
The SDK retries a transient failure up to two additional times (three attempts total) before raising an exception.
What's the default timeout if I don't set it?
600.0 seconds (10 minutes), applied per attempt.
Does with_options() change the original client?
No.
client.with_options(...) returns a new object with the overrides applied; the original client and its defaults are untouched.
Does timeout apply to the whole retry sequence or just one attempt?
Just one attempt.
If every attempt times out and gets retried, the worst-case wall-clock time can reach roughly timeout × (max_retries + 1).
Will the SDK retry a 400 Bad Request?
No.
400, 401, 403, and 404 are treated as non-retryable, since the request itself (not the network or server) is the problem, and retrying it unchanged would fail again.
Is retry/timeout configuration different between Anthropic() and AsyncAnthropic()?
No.
Both client classes accept the same max_retries and timeout constructor arguments and support the same with_options(...) pattern.
Does a 429 response respect the API's retry-after header?
Yes.
When the response includes a retry-after header, the SDK honors it as a minimum delay before the next retry attempt.
Should I set max_retries to 0 for a health check?
That's a reasonable choice.
A health check usually wants to know immediately whether the API is reachable, rather than masking a real outage behind several retry attempts.
Can I set a different timeout for streaming vs non-streaming calls?
Yes, using the same with_options(timeout=...) pattern per call, or by setting different timeouts on separate client instances if the split is consistent across your application.
Does raising max_retries fix a slow response that eventually succeeds?
Not directly.
max_retries addresses failures, not slowness; a request that succeeds but is simply slow is a timeout concern, and for large outputs, switching to streaming is usually the better fix.
What exception do I catch if retries are exhausted?
The typed exception matching the underlying failure - for example anthropic.RateLimitError for exhausted 429 retries, or anthropic.APIConnectionError for exhausted network-error retries. See the exception reference page for the full mapping.
Stack versions: Written against the Claude model lineup current as of ~June 2026 - Claude Fable 5, Claude Opus 4.8, Claude Sonnet 5 (the default), and Claude Haiku 4.5 - and the official anthropic Python SDK (latest 0.x release). Model names, SDK versions, and pricing move quickly - verify current specifics at platform.claude.com/docs before relying on them.
Reviewed by Chris St. John·Last updated Jul 19, 2026