Skip to main content
For the actual limits per plan, see Rate limits. This guide is the playbook for handling them in real applications.

The two failure modes

Don’t blanket-retry. Retrying caller errors burns RPM for nothing.

Always honour Retry-After

Every 429 from us includes:
The number is seconds until your window frees. Use it directly — don’t override with your own delay.
python

Exponential backoff with jitter (for 5xx)

For upstream transients without Retry-After:
python
Jitter (+ random()) is critical — without it, every client retries at the same instant and you get a stampede.

Don’t retry 4xx

400/401/403/422 are deterministic — retrying just wastes RPM and money. Fix the request, then resubmit. Common offenders:
  • Wrong model slug → check GET /v1/models
  • Missing required parameter → check the endpoint reference
  • Image too large → resize before resending
  • Malformed JSON → fix the producer

SDK-level retries

The OpenAI SDK retries 429s and 5xx automatically:
python
This honours Retry-After. For most apps, this is enough — you don’t need a custom loop. But:
  • It retries on a single call. Bursty workloads still need a queue.
  • It applies to streaming too — the first chunk is what matters.

Stay under the limit on purpose

Reactive retry is the floor. Proactive limiting is the ceiling. Token-bucket on your side, capped at ~80% of the key’s RPM:
python
Result: zero 429s under steady load. Bursts above 120 rpm spike → bucket pauses → resumes when refilled. Queue any requests that need to go through.

Fallback chains: the better answer for production

Per-call retries help, but fallback chains help more. Configure once:
Now a 429 on gpt-4o is invisible to your code — the gateway routes to gpt-4o-mini, and you see:
This shifts retry from your client to the gateway, with sub-100 ms hop instead of an exponential wait. Combine with exponential backoff for the case when all fallbacks are also rate-limited.

Per-environment keys

Don’t share one key across dev/staging/prod. Reasons:
  • Dev experiments shouldn’t drain prod’s RPM budget
  • Leaked dev keys have lower blast radius if scoped to a low-RPM preset
  • Per-env analytics are clearer
Settings → API Keys → Create. Pick a quota preset per environment.

Daily token caps

Some plans cap total tokens per day in addition to RPM. Hitting the cap returns 429 too — but Retry-After will be the seconds until midnight UTC, not seconds. Don’t blindly sleep — instead:
  • Reduce request volume
  • Switch to a cheaper model
  • Top up to a higher plan
You’ll see code: "rate_limit_exceeded" and message: "Daily token cap reached" to distinguish from RPM 429s.

When backoff fails

If you back off twice and still 429:
  1. Look at Settings → Usage → By key — is one key dominating?
  2. Check Settings → API Keys → preset — is the preset lower than you remember?
  3. Did you ship a loop without rate limiting? Look at request volume in the last hour.
  4. Open a ticket — sometimes it’s our problem and we want to know.