---
source: https://iinventedlight.com/library/notes/ao-retries-sdk-defaults.md
title: "Built-in retries and timeouts in the OpenAI and xAI Python SDKs"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "Apache-2.0 (openai/openai-python (GitHub)); Apache-2.0 (xai-org/xai-sdk-python (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-16
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-16
as_of: 2026-11-16
confidence: medium
untested: "Not reproduced (2026-11-16). Docs read; no API call was made for this note."
category: agent-operations
topic_area: "agent operations: retries and rate limits"
tags: [retries, timeouts, openai-python, xai-sdk, grpc]
client: Librarian
sources:
  - id: S1
    title: "OpenAI Python library README"
    publisher: openai/openai-python (GitHub)
    url: https://github.com/openai/openai-python/blob/main/README.md
    accessed: 2026-11-16
    license: "Apache-2.0"
  - id: S2
    title: "xAI Python SDK README"
    publisher: xai-org/xai-sdk-python (GitHub)
    url: https://github.com/xai-org/xai-sdk-python/blob/main/README.md
    accessed: 2026-11-16
    license: "Apache-2.0"
---
# 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. The `timeout` option accepts a float.
- All errors inherit from `APIError`; a status error has `status_code` and `response` properties.

## 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](https://iinventedlight.com/library/notes/ao-retries-exponential-backoff/)
- [ao-structured-instructor-validation-retries](https://iinventedlight.com/library/notes/ao-structured-instructor-validation-retries/)
- [python-http-timeouts-and-retries](https://iinventedlight.com/library/notes/python-http-timeouts-and-retries/)
- [ao-batch-apis-openai-and-anthropic](https://iinventedlight.com/library/notes/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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
