What this thread does
Do first: Add from openai import OpenAI, RateLimitError from the page's Python retry example.
When you need it
Use this fallback pattern when a Responses API request encounters rate limits. Tenacity adds random exponential delays, and the example bounds attempts while disabling the SDK's separate retry layer.
Steps
1. Import the page's retry components and disable built-in retries:
from openai import OpenAI, RateLimitError
from tenacity import (
retry,
retry_if_exception_type,
stop_after_attempt,
wait_random_exponential,
)
client = OpenAI(max_retries=0)
2. Wrap the Responses call with the page's retry policy:
@retry(
retry=retry_if_exception_type(RateLimitError),
wait=wait_random_exponential(min=1, max=60),
stop=stop_after_attempt(6),
reraise=True,
)
def response_with_backoff(**kwargs):
return client.responses.create(**kwargs)
3. Before using this fallback example, add handling for valid Retry-After hints as the page requires. The Python snippet does not include that handling; the page does not supply a Python implementation of it. 4. The page demonstrates calling the wrapper as follows:
response = response_with_backoff(
model="gpt-6-luna",
input="Say hello in one sentence.",
reasoning={"effort": "none"},
max_output_tokens=64,
)
print(response.output_text)
Check it worked
The Python example prints response.output_text; the page does not provide a fixed response text for this example.
Limits
This is fallback backoff, not a complete server-hint-aware Python implementation. The page says valid Retry-After hints must be handled so retries do not happen too early. Disable SDK retries or include them in the application's retry limits. Unsuccessful requests still count toward per-minute limits. Tenacity is a third-party library whose behavior and security the page asks you to review. The page does not name a version for this Python pattern.
Not for: deciding whether a 429 means exhausted quota or a retryable rate limit; see openai-429-error-quota-or-rate-limit-which-to-retry.
Sources
- Rate limits, OpenAI API documentation, read 2026-11-24: "The Python examples below demonstrate fallback backoff."
Checked
2026-11-24; read <https://platform.openai.com/docs/guides/rate-limits>; no command was run.
Started from a post by @OpenAI, packaged by the editor. Original post