AI API rate limits are the guardrail every developer hits sooner or later. You ship a feature, traffic grows, and one busy afternoon your app starts getting 429 errors at the worst possible moment. The instinct is to retry the failed call right away, and that instinct is exactly what turns a small hiccup into a full outage. A retry policy is not a nice-to-have. It is part of the client, as important as the request itself.
How AI API Rate Limits Actually Work
Most AI providers limit you on two axes at once: requests per minute and tokens per minute. A chat completion with a long answer can burn your token budget in a handful of calls even if your request count looks low. Some providers also cap concurrent requests, so ten calls in flight can trip a limit that ten sequential calls would never touch.
Limits usually sit at the API key or project level, and they change with your plan tier: a free tier might allow a few requests a minute, a paid tier raises the ceiling but never removes it. Providers also distinguish a short burst from sustained load. You can exceed the average rate for a few seconds, but keep it up and the 429s start.
A 429 is not an error in your code. It is the provider saying “slow down.” The correct response is to slow down, not to try the same request again a millisecond later.
Why Retrying Immediately Makes Things Worse
Picture a service with a hundred users hitting the same limit at once. Every client retries instantly, so the provider now sees two hundred requests instead of one hundred. Half of those fail again, the clients retry again, and within seconds the load is several times the original traffic. This is a retry storm, and it is the reason a brief limit can turn into minutes of errors.
The damage goes beyond errors. Every retried request that gets through consumes tokens, and a loop that retries a heavy prompt five times has spent five times the budget for one answer. It also slows everything else down: queued requests pile up behind the retries, so users wait longer for responses that were never at risk. If you have ever wondered what slow responses actually cost users, retry storms are one of the quieter causes.
Worst case, aggressive retrying looks like abuse. Some providers escalate from short 429s to longer lockouts or temporary key suspension when a client keeps hammering a limit. The retry that was supposed to save the request is what gets the key blocked.
Exponential Backoff: Wait Longer After Each Failure
Exponential backoff is the standard answer, and it works because it spreads retries over time instead of clustering them. The idea is simple: after the first failure, wait a short interval. After the second, wait roughly twice as long. After the third, twice again, up to a cap.
A common shape is a base delay of one second, doubling each time, capped at around 30 to 60 seconds. So the waits look like 1s, 2s, 4s, 8s, 16s, then 30s, 30s. The cap matters: without it, a long outage pushes waits into minutes and the user has already given up.
Backoff alone is not enough: if every client uses the same base delay and doubling, they still retry in lockstep.
Add Jitter So Your Clients Do Not Retry in Lockstep
Jitter means adding randomness to each wait so retries spread out instead of landing at the same moment. Without it, a hundred clients that failed at the same second will all retry at the same second again, and the storm repeats on a schedule.
The simplest version is full jitter: instead of waiting the full backoff interval, wait a random amount between zero and that interval, so a 4-second backoff becomes a random wait between 0 and 4 seconds. Equal jitter waits half the interval plus a random amount up to the other half. Either one breaks the synchronization.
In practice, exponential backoff with jitter is a one-line change, and it is often the difference between a retry policy that works under real load and one that only works in a single-client test. Check whether your HTTP library adds jitter by default. Many do not.
Respect the Retry-After Header
When a provider returns a 429 too many requests response, it often tells you exactly how long to wait. The Retry-After header carries either a number of seconds or a date, and that value is the provider’s own instruction. Honor it before your backoff math. If the header says 20 seconds, wait 20 seconds, even if your next backoff step would have been 4.
Some providers also send custom headers with remaining quota or reset times, such as how many requests you have left in the current window. Log those headers. They are the earliest warning that you are close to a limit, and they let you slow down before the 429s start instead of after.
One caveat: if Retry-After says to wait an hour, that is usually a sign of a harder block. Surface the problem to the user instead of silently waiting. Either way, retries need a budget.
Set a Budget: Max Attempts, Timeouts, and Idempotency
A retry policy without a limit is just a slower infinite loop. Decide up front how many attempts a request gets and how long the whole effort can take. Three to five attempts with a total deadline of 30 to 60 seconds is a reasonable default for interactive features; background jobs can afford more, but they still need a deadline.
Two rules keep retries safe. First, only retry errors that might succeed on a second try: 429s, 502s, 503s, and network timeouts. Never retry a 400 or 401. A malformed request will fail the same way every time, and retrying it just burns quota. Second, make retries idempotent where you can. If the provider supports idempotency keys, send one, so a retry that arrives after the first request actually succeeded does not create a duplicate charge or a duplicate side effect.
The same thinking applies beyond API calls. An agent stuck in a loop needs step limits and timeouts for the same reason: without a ceiling, a small failure compounds until something breaks. A retry budget is the same guardrail, applied to one request instead of a whole workflow.
Design Around the Limit Instead of Fighting It
The best retry policy is the one that rarely fires. A few design choices cut your exposure more than any backoff formula.
- Queue requests instead of firing them all at once. A small client-side queue with a concurrency limit keeps your request rate smooth. Bursts are what trip limits; a queue turns bursts into a steady stream.
- Cache repeated prompts. If the same question gets asked many times, a semantic cache can answer from earlier results without calling the API at all. Every cached answer is a request that never touches your quota.
- Batch where the API allows it. Some endpoints accept multiple inputs in one call, which counts once against a requests-per-minute limit.
- Track your usage. Log token consumption per feature and per user so you can see which part of the product is eating the budget. If you do not already track your AI API costs, start there; a retry policy cannot fix a feature that is simply too expensive to run.
- Degrade gracefully. When retries are exhausted, show a clear message and a way to try again later. An honest “the AI service is busy, try again in a minute” beats a spinner that never resolves.
A Retry Policy You Can Copy Today
Here is a starting point for most interactive apps calling an AI API:
| Setting | Value | Why |
|---|---|---|
| Retryable errors | 429, 502, 503, timeouts | Only errors that might clear on their own |
| Max attempts | 4 total (1 try + 3 retries) | Enough to ride out a blip, short enough to fail fast |
| Backoff | Exponential, base 1s, cap 30s | Spreads load without stalling the user |
| Jitter | Full jitter on every wait | Stops clients retrying in lockstep |
| Retry-After | Always honored, overrides backoff | The provider knows its own limits |
| Total deadline | 60 seconds | Bounds the worst case for the user |
Tune the numbers for your case. A background batch job can use more attempts and a longer deadline. A chat interface probably wants fewer attempts and a faster failure so the user can rephrase or try again. What matters is that the numbers are chosen deliberately and written down, so the next person who touches the client knows the policy exists and why it looks the way it does.
Rate limits are not a punishment. They keep the service usable for everyone, including you. A client that backs off, adds jitter, honors Retry-After, and knows when to stop rarely gets locked out.