Built-in retries and timeouts in the OpenAI and xAI Python SDKs
Answer: Both SDKs retry certain errors automatically, with exponential backoff.
| SDK | Default retries | Default timeout | |---|---|---| | openai Python | 2 times, short exponential backoff | 10 minutes | | xai_sdk | up to 5 attempts on UNAVAILABLE | 27 minutes (1620 seconds) |
openai-python
- Connection errors, 408 Request Timeout, 409 Conflict, 429 Rate Limit and >=500 Internal errors are retried by default, only when the body can be safely resent.
OpenAI(max_retries=0)disables retries;client.with_options(max_retries=5)sets them per request. Thetimeoutoption accepts a float.- All errors inherit from
APIError; a status error hasstatus_codeandresponseproperties.
xai-sdk
- Backoff starts at 0.1 seconds, with multiplier 2, up to a maximum of 1 second between attempts.
- You can disable retries by setting a channel option to
0, or configure your own retry policy with a gRPC service config JSON string. - The timeout applies to all RPCs of a client and cannot be set for an individual method.
See also
- ao-retries-exponential-backoff
- ao-structured-instructor-validation-retries
- python-http-timeouts-and-retries
- ao-batch-apis-openai-and-anthropic
Claims
- id: C1 claim: openai-python retries twice by default. source: S1 evidence: "automatically retried 2 times by default"
- id: C2 claim: openai-python times out after 10 minutes. source: S1 evidence: "By default requests time out after 10 minutes."
- id: C3 claim: xAI SDK allows up to 5 attempts. source: S2 evidence: "for a total of up to 5 attempts"
- id: C4 claim: xAI default timeout is 27 minutes. source: S2 evidence: "The default timeout is 27 minutes (1620 seconds)."
Sources
- [S1] OpenAI Python library README. openai/openai-python (GitHub). https://github.com/openai/openai-python/blob/main/README.md . License: Apache-2.0. Accessed 2026-11-16.
- [S2] xAI Python SDK README. xai-org/xai-sdk-python (GitHub). https://github.com/xai-org/xai-sdk-python/blob/main/README.md . License: Apache-2.0. Accessed 2026-11-16.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: openai/openai-python (GitHub), OpenAI Python library README, Apache-2.0 (https://raw.githubusercontent.com/openai/openai-python/main/LICENSE); xai-org/xai-sdk-python (GitHub), xAI Python SDK README, Apache-2.0 (https://raw.githubusercontent.com/xai-org/xai-sdk-python/main/LICENSE). Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: openai/openai-python (GitHub), OpenAI Python library README, Apache-2.0 (https://raw.githubusercontent.com/openai/openai-python/main/LICENSE); xai-org/xai-sdk-python (GitHub), xAI Python SDK README, Apache-2.0 (https://raw.githubusercontent.com/xai-org/xai-sdk-python/main/LICENSE).
Cite this
iinventedlight. 2026. "Built-in retries and timeouts in the OpenAI and xAI Python SDKs." iinventedlight Library, iil:note:66czavdg, version of 2026-11-16. https://iinventedlight.com/library/notes/ao-retries-sdk-defaults/. License: CC-BY-4.0.
@misc{iil_note_66czavdg,
author = {{iinventedlight}},
title = {{Built-in retries and timeouts in the OpenAI and xAI Python SDKs}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-16},
url = {https://iinventedlight.com/library/notes/ao-retries-sdk-defaults/},
note = {Permanent ID iil:note:66czavdg. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/ao-retries-sdk-defaults.md.