Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4133 pages

AI for developers

OpenAI Python SDK Retry Defaults, Compared With the Anthropic and Google Gen AI SDKs

In short

The OpenAI Python SDK retries certain errors twice by default with exponential backoff, and requests time out after 10 minutes. The Anthropic SDK uses the same two numbers. The Google Gen AI SDK counts attempts including the first request, uses milliseconds for timeouts and documents a default of 5 attempts. Copying one config to another changes the request count.

What does the OpenAI Python SDK retry by default, and how do the others compare?

One number that looks identical across three SDKs, retries, does not mean the same thing, and the timeout comes in two different units. The versions behind these pages were the latest on PyPI on 20 Nov 2026: openai 3.57.0, anthropic 2.11.0 and google-genai 3.6.1.

SDKDefault retry settingWhat the number countsDefault timeoutTimeout unit
OpenAI Pythonmax_retries is 2Retries after the first request10 minutesSeconds, as a float or an httpx2.Timeout object
Anthropic Pythonmax_retries is 2Retries after the first request10 minutesSeconds, as a float or an httpx2.Timeout object
Google Gen AI Pythonattempts is 5 when retry options are set without a valueAttempts including the original request; 0 or 1 means no retriesThe reference states no defaultMilliseconds, as an integer in HttpOptions

Checked against: source 1, source 2, source 3, source 4, source 5, source 6

Which failures are retried?

OpenAI and Anthropic list the same set: connection errors, 408 Request Timeout, 409 Conflict, 429 Rate Limit and any status of 500 or above. OpenAI adds that a request is retried only when its body can be safely resent.

Google's reference describes a default set of 408, 429 and 5xx codes that may be used when you do not list your own, and you can supply http_status_codes yourself. A 409 is absent from that default set, which is a visible difference from the other two.

The Google page documents these defaults for the retry options object. It does not say whether a client created without retry_options retries at all, so check that before assuming it does.

Checked against: source 1, source 2, source 3

How long does the SDK wait between attempts?

OpenAI and Anthropic say only that they use a short exponential backoff and give no figures.

Google publishes the parameters. The first delay is 1.0 second, each delay is multiplied by 2.0 after an attempt, no delay exceeds 60.0 seconds and a jitter factor of 1.0 adds randomness.

Checked against: source 1, source 2, source 3

How do timeouts and retries combine?

Both OpenAI and Anthropic state that a request that times out is retried twice by default. Taken together with the 10-minute default, a call that keeps timing out can occupy a worker for about three timeout periods before an error reaches your code. That sum is my arithmetic from their two statements, not a number either page prints.

Setting a short timeout without lowering max_retries multiplies the waiting. Setting max_retries to 0 and handling the failure in your own queue is the other common choice, and both SDKs document it.

Checked against: source 1, source 2

What about long requests and streams?

Anthropic warns against a large max_tokens on a non-streaming request, because some networks drop idle connections. Its SDK raises a ValueError when a non-streaming request is expected to take longer than roughly 10 minutes, and passing stream true or overriding the timeout removes the error. The SDK also sets a TCP keep-alive option.

OpenAI says stream consumption is not retried automatically, because replaying a request could duplicate output your application has already received. A read timeout during a stream raises APITimeoutError, and other transport failures raise APIConnectionError. The Anthropic page I read does not describe retries once a stream has started.

Checked against: source 1, source 2

Which settings should you decide on purpose?

Write the retry policy down per client rather than inheriting a default.

  • Translate the count: max_retries of 2 means up to 3 requests, while attempts of 3 on Google means 3 requests.
  • Convert units: 20 seconds is 20.0 in the OpenAI and Anthropic SDKs and 20000 in Google's HttpOptions.
  • Decide whether a 409 should be retried, since only two of the three SDKs list it.
  • Decide who owns retries when a gateway or a queue also retries, so one failure is not retried at every layer.

Checked against: source 1, source 2, source 3

What else do people ask?

Do the SDKs retry a request that returned a 400 error?

The retry lists in the three pages cover connection errors, 408, 409, 429 and server errors. A 400 is not on any of them, so it is raised to your code.

Can I turn retries off?

Yes. Set max_retries to 0 on OpenAI or Anthropic. On Google, set attempts to 0 or 1, which the reference says means no retries.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. This page compares the three SDKs' own documentation, which I read on 20 Nov 2026. I did not install the SDKs or trigger failures to watch the retries happen, so it reports documented defaults, not observed behaviour. It covers the Python SDKs only, and the OpenAI text comes from the main-branch README, which can be ahead of the released version. Found a mistake? Tell me.

Keep reading

Next step

Have a project in mind?

Tell me about it. A discovery call within 48 hours.