For a temporary OpenAI rate limit, the useful questions are which limit applied, how long the server asks you to wait, and how much retry budget your operation has left. HTTP 429 alone does not answer them: billing failures also use 429 and require a different response.
Read the status, code, and headers together
429with a request or token rate limit- Pace requests and inspect available rate-limit and
Retry-Afterheaders. Limits can apply to requests, tokens, images, audio, or longer accounting periods; the model and account settings matter. 429,rate_limit_error,slow_down- The request rate increased too quickly. Reduce it, follow
Retry-Afterwhen present, and ramp gradually. The current error guide documents this as 429. 503,service_unavailable_error,server_is_overloaded- The requested model is temporarily overloaded. Follow the server's retry guidance and use a bounded policy.
- Credit, spend-limit, or usage-limit codes
- Waiting does not restore account access. Follow the billing-error decision table, including when the broader type is
insufficient_quota.
The previous version of this page described a 503 “Slow Down” response and a fixed 15-minute recovery rule. That advice does not match the current error-code guide and has been removed. Likewise, a reset is not universally one minute: OpenAI documents several limit dimensions and reset durations.
Find the bottleneck before changing the model
OpenAI applies limits at organization and project level, with model-specific and sometimes shared-family limits. A new key in the same limited scope does not create independent capacity. Compare request and token usage across services, not just the failing worker. A burst can exceed a shorter enforcement interval even when its average looks acceptable over a minute.
The rate-limit guide documents headers such as x-ratelimit-limit-requests, x-ratelimit-remaining-tokens, and x-ratelimit-reset-tokens, plus project-scoped headers where available. Treat their reset values as documented durations, not a timestamp or a promise of a fixed 60-second window. Record the actual headers your endpoint returns; do not invent missing values.
- Request pressure: use a queue, constrain concurrent starts, and avoid synchronized scheduled jobs.
- Token pressure: inspect full prompt size and the output allowance used for admission. Reduce unnecessary context and choose an endpoint-appropriate output cap.
- Acceleration pressure: restore a stable rate and increase gradually instead of releasing the whole backlog.
- Sustained capacity shortage: inspect the current limits page and approved tier. A cheaper model does not automatically have independent or higher limits.
Batch processing can be appropriate for work that can wait, where the selected model and endpoint support it. It is a separate workflow with its own documented limits. Do not copy the legacy Completions prompt-array example into a Responses request.
Bound retries in attempts and time
Use one retry owner. OpenAI's official Python SDK documentation currently describes two automatic retries by default for eligible errors, including 429 and server errors, when the body can be safely resent. An outer retry loop can multiply those attempts. Configure max_retries=0 if your application owns the policy, and set an explicit transport timeout.
This Python helper plans a delay after a failed attempt. attempt=0 means the initial attempt just failed; max_attempts=3 permits at most two more attempts. A valid Retry-After is a minimum, including an HTTP date. If waiting would consume the remaining budget, the function returns None so the caller can stop or defer the operation.
"""Plan a delay after a failed attempt, without performing network I/O."""
import math
import random
from datetime import datetime, timezone
from email.utils import parsedate_to_datetime
def retry_delay(attempt, remaining_seconds, *, max_attempts=3,
retry_after=None, now=None, jitter=None):
if type(attempt) is not int or attempt < 0:
raise ValueError("attempt must be a nonnegative integer")
if type(max_attempts) is not int or max_attempts < 1:
raise ValueError("max_attempts must be a positive integer")
if isinstance(remaining_seconds, bool) or not math.isfinite(remaining_seconds):
raise ValueError("remaining_seconds must be finite")
if attempt + 1 >= max_attempts or remaining_seconds <= 0:
return None # No sleep after the last allowed attempt.
minimum = 0.0
if isinstance(retry_after, str):
raw = retry_after.strip()
if raw.isascii() and raw.isdigit():
try:
minimum = float(raw)
except ValueError:
return None
else:
try:
target = parsedate_to_datetime(raw)
current = now or datetime.now(timezone.utc)
if target.tzinfo is not None:
minimum = max(0.0, (target - current).total_seconds())
except (TypeError, ValueError, OverflowError):
pass # An invalid header supplies no server minimum.
fraction = random.random() if jitter is None else jitter
if isinstance(fraction, bool) or not math.isfinite(fraction) or not 0 <= fraction <= 1:
raise ValueError("jitter must be between zero and one")
delay = max(minimum, fraction * 2 ** min(attempt, 3))
return delay if delay < remaining_seconds else None
Locally tested, without provider requests: tests cover attempt exhaustion, integer and HTTP-date headers, past dates, malformed headers, nonfinite values, deterministic jitter, and a server delay that exceeds the local budget. This is a scheduling function, not an SDK wrapper. Recompute the remaining time with a monotonic clock after each failed attempt; apply a request timeout and cancellation policy separately. It cannot cancel an in-flight operation.
Use the structured classifier in the billing guide before scheduling a retry. Do not retry an unknown response just because a helper can produce a delay. If a streamed response was partially delivered, preserve that partial result and inspect endpoint recovery semantics before resending; replaying can duplicate downstream work.
What to measure after the incident
Track initial requests separately from retries, queue wait separately from provider latency, and failed completions separately from successful outputs. OpenAI notes that unsuccessful requests can still consume per-minute limits. A rising retry count can worsen congestion while making the original workload look smaller than it is.
Keep the model ID, endpoint, project, structured error code, request ID, relevant headers, attempt number, and elapsed time. Keep prompts and credentials out of routine logs. Compare capacity changes against the real workload cost, and test a fallback's capabilities before enabling it in an incident.