SalpXXAPI News
Integrations 2 min read

The OpenAI SDK retries twice and times out after 10 minutes by default: change both before using a gateway

Official openai-python defaults to a 10-minute timeout and 2 automatic retries, retrying connection errors, 408, 409, 429 and 5xx, but not errors while consuming a stream. When using a gateway, set timeout and max_retries explicitly per task type to avoid duplicate charges and long hangs.

Bottom line

Official openai-python defaults to a 10-minute request timeout, raising APITimeoutError on timeout, and 2 retries with short exponential backoff. Retried errors include connection errors, 408, 409, 429 and >=500. Errors while consuming a streamed response are not retried, because replaying could duplicate output already received.1

These defaults suit direct, short chats. Through a gateway, on long tasks or on per-call image and video endpoints, they can backfire: one failure quietly becomes three requests, or one stuck connection holds for 10 minutes. Configure explicitly by task type instead of relying on defaults.

Where the defaults go wrong

1. Retries multiply calls

max_retries=2 means one logical call can send up to 3 HTTP requests. For token-billed chat, a failed request usually produces no output. But for per-call tasks the server has already started, such as image generation, a client-side timeout followed by a retry may land after the server finished the first attempt. Whether that is charged twice depends on the provider's rules; do not assume a refund.

2. Ten minutes is too long or too short

An interactive user will not wait 10 minutes; fail earlier and say so. High-resolution images or long generations may take minutes, so an overly short timeout causes pointless retries. SalpX docs explicitly recommend a client timeout of at least 300 seconds for image endpoints, warning that 30 or 60-second defaults will cut off.3

3. 429 is retried by default

The SDK retries 429 automatically. If the server sends Retry-After, it states a suggested wait as an HTTP date or non-negative seconds, though MDN notes support is still inconsistent.2 When your own concurrency is over the limit, short-backoff retries only extend the throttling; reduce concurrency at the application layer.

  1. Interactive chat: timeout 30–60 seconds, max_retries 1–2. The user sees "try again later" rather than a hang.
  1. Batch or offline jobs: timeout at 1.5x the longest single item; max_retries can be higher, but log each retry at the application layer for reconciliation.
  1. Per-call image or video tasks: max_retries=0, letting business code decide whether to resubmit; set the timeout from the provider docs (SalpX recommends 300s+ for images).3
  1. Streaming output: remember a mid-stream drop is not retried automatically. To continue, the business layer must decide whether to resend and handle the partial content already received.1

The official SDK supports global settings and per-request overrides:

from openai import OpenAI

client = OpenAI(
    base_url="https://www.salpx.com/v1",
    timeout=60.0,
    max_retries=1,
)

# Per-request override: no retries and a longer timeout for per-call tasks
client.with_options(timeout=300.0, max_retries=0).images.generate(
    model="<model name>", prompt="..."
)

What to check when reconciling

  • Log each HTTP attempt's time, status code and request ID, not only the final result.
  • When one logical task maps to several usage records, first check whether the SDK retried automatically.
  • For 429, log the Retry-After value and the actual wait to tell insufficient backoff from excessive concurrency.

In one line

SDK defaults are built for general use. On a gateway, set timeout and max_retries per task type, turn off automatic retries for per-call tasks and log every attempt. That is how the bill ends up matching.

Sources & attribution

This article references the public materials listed below. Analysis and wording are SalpX's own; quoted material remains the property of its original authors and publishers.

  1. openai-python README — OpenAI (GitHub) · accessed 2026-11-28Note:Official SDK docs: default timeout 10 minutes, 2 retries with short exponential backoff; connection errors, 408, 409, 429 and >=500 are retried; errors while consuming a stream are not; OPENAI_BASE_URL can replace base_url.
  2. Retry-After header - HTTP — MDN Web Docs · accessed 2026-11-28Note:MDN: Retry-After is used with 429 and 503 and is either an HTTP date or non-negative seconds; support is still inconsistent.
  3. SalpX API Reference — SalpX · accessed 2026-11-28Note:SalpX official docs: Base URL, Bearer auth, image size tiers, 4K model names, the clamp response header, and integration notes such as a 300s+ timeout, a 10 MB response budget and publicly downloadable reference images.

One key for Claude, GPT and 50+ models

The SalpX gateway is OpenAI-SDK compatible. Point base_url at https://www.salpx.com/v1 and you are done.