Kolkata ·  
AI engineering
production
short · 3 min

Retries

Retrying failed calls with backoff, jitter and timeouts, without making an outage worse.

updated 29 Sept 2026

Picture the provider having a bad ten minutes. Our app sends a call and gets back a 503: the model is overloaded. Most of the time, the same call a moment later would go through. So we try again. That's a retry, and done carelessly it turns a small blip into a big one. Let's follow that failed call and make each decision as it comes.

Is this worth retrying?

A retry only helps if the same request could succeed later. A 503 overload, other server errors, timeouts, dropped connections, a 429 from a rate limit: all of those can pass. A malformed request, a prompt that's too long, a bad API key: those fail the same way every time. Same for quota and billing errors, even when they arrive as a 429 that looks like a rate limit. So check the error code in the body, not just the status.

How long do we wait?

Not zero. Retrying in a tight loop piles load on a struggling server, and on OpenAI failed requests even count against our limit.

So we back off: wait a little after the first failure, and multiply the wait each time, up to some cap. That's exponential backoff.

But imagine a thousand clients that all failed at the same moment. If they all back off by the same amounts, they all come back at the same moment and knock the server over again. So we add randomness to each wait, called jitter, and the retries spread out.

And if the response has a Retry-After header, it tells us the minimum. Wait at least that long, plus a little randomness. OpenAI's own example uses random exponential waits between 1 and 60 seconds, stopping after 6 attempts. Cap the total time too, not just the count.

How many times?

Fewer than you'd think. Google's SRE team uses two caps. Per request, at most three attempts; if it failed three times, the whole service is probably overloaded. Per client, retry only while retries are under 10% of its requests. When a service is rejecting most traffic, the three-attempt cap alone lets load climb to nearly three times normal. The 10% budget keeps it around 1.1 times.

Who's retrying?

This is the one that bites LLM apps. Retries multiply across layers. Official SDKs like OpenAI's already retry 429s and 503s on their own. Then we wrap the call in our own retry loop. Then a gateway tries other models as a fallback.

One question becomes 27 provider calls in the middle of an outage. Amazon's version has five layers each retrying three times: 243 times the load on the database at the bottom. The advice from Google and Amazon is the same: retry at one layer. If we write our own loop, we turn the SDK's retries off or count them.

When not to retry at all

Some calls have side effects. If the model's reply triggers a tool that sends an email or charges a card, a timeout doesn't tell us whether it happened, so a retry can do it twice. Only retry what's safe to repeat, or make it safe with an idempotency key our code checks.

Streams are another case. A stream can fail halfway, after the user has seen half an answer. Don't silently replay it; show an error or a clear restart.

And there's one thing nobody has a neat answer for yet: the timeout itself. The usual advice is to set it from the downstream service's slowest normal latency, like p99.9. But an LLM call can take under a second or several minutes, depending on the answer's length. One fixed timeout either cuts off long answers or sits too long on a stuck one, and the sources here don't settle which way to lean.

Further reading