Retrying a failed LLM call is good advice. Retrying it in three different places is a common accident. Each layer looks reasonable on its own: "try three times" is a sensible default. But retries in different layers multiply. Three layers of three attempts mean one request can make 27 calls before anything gives up, and on a bad day you pay for most of them.

A few words first

A token is a chunk of text, roughly three quarters of an English word. APIs bill per million tokens: input is what you send, output is what the model writes. A retry means sending the same request again after a failure. A transient error is one that goes away by itself, like a dropped connection. A timeout is your client giving up waiting for a response. The model on the other end may still be generating, and you may still be billed.

Where the layers come from

Nobody writes 27 retries on purpose. They pile up:

  1. The SDK. Many official client libraries retry some failures on their own before your code ever sees an exception. Look up max_retries (or its equivalent) in your SDK's docs. It is often on by default.
  2. Your code. You wrap the call in a retry helper or a for attempt in range(3) loop, because the tutorial said to.
  3. The job queue. The task runs in a background worker (Celery, RQ, a cloud queue). The worker marks the task failed, and the queue retries it three times.
  4. Sometimes a fourth. A nightly cron job reruns everything that "didn't finish".

Each layer sees one failure and starts its own round, never knowing the layer below already tried three times.

The numbers

I wrote a short script for this. One call is 2,000 input tokens and 500 output tokens. Prices are gpt-5.6 list prices, $2 per million input and $12 per million output, from the catalog snapshot of the LLM gateway I work on. That makes one attempt cost $0.0100. Each layer makes 3 attempts with a 30-second timeout and backoff waits of 1 and 2 seconds. The doomed request is one that can't succeed: the provider is overloaded and every attempt times out after the model has already done the work. I assume each such attempt is billed in full.

Retry setup Attempts per doomed request Cost per doomed request Time until it gives up
SDK only 3 $0.03 1.6 min
SDK + your loop 9 $0.09 4.7 min
SDK + loop + queue 27 $0.27 14.2 min
SDK + loop + queue + cron rerun 54 $0.54 28.3 min

Now spread that over an outage. An app with 1,000 requests an hour normally spends $10 an hour on this call. If the provider struggles for one hour, the three-layer setup sends 27,000 attempts to an already overloaded service, and the bill for that hour is $270.

What the extra layers buy

Here's the other half. Suppose errors are random and independent: each attempt fails 5% of the time, regardless of the previous one. Then one layer with three attempts leaves a request unanswered only if all three fail: 0.05³, or 125 requests per million. A second layer brings that down to effectively zero. The third and fourth layers have nothing left to fix.

On a normal day, extra layers cost almost nothing: expected attempts per request are 1.0525 with one layer and 1.0526 with four. That's why the problem stays invisible. Extra layers do nothing for random errors and multiply your bill when errors aren't random: when the provider is down, rate-limiting you, or too slow for your timeout.

What to do instead

Retry in exactly one place, and give that place a budget in time, not just a count:

import time RETRYABLE = (TimeoutError, ConnectionError) # plus your SDK's rate-limit / 5xx errors def call_with_budget(send, deadline_s=60, max_attempts=3): start = time.monotonic() for attempt in range(max_attempts): try: return send() except RETRYABLE: if time.monotonic() - start + 2 ** attempt > deadline_s: break time.sleep(2 ** attempt) raise RuntimeError("LLM call failed; not retrying further") 

Then switch the other layers off for this call. Set the SDK's own retries to zero if your helper does the retrying, or delete your loop and trust the SDK. Then tell the queue that this task is not retryable (most queues have a per-task setting), or let it retry only after a long delay. Retry only errors that can go away: timeouts, connection drops, rate limits, server errors. A "request too large" or "invalid API key" error will fail the same way every time.

If many requests start failing at once, stop sending for a minute instead of retrying each one. This is called a circuit breaker: after N failures in a row, fail fast for a while, then let one test request through.

What this doesn't solve

A single retry layer doesn't make an unreliable provider reliable. During a real outage your users still get errors, just cheaper ones. If you need answers during an outage, you need a fallback model, which is a different trade-off with its own price list.

The "billed in full on timeout" assumption is the worst case. Some providers stop generating when the client disconnects, some bill only what was generated, and rejected requests (like most rate-limit errors) usually cost nothing. Check your usage dashboard after a bad hour to see which case you're in. The 27× attempt count holds either way, and so does the 14-minute wait.

Finally, "independent 5% errors" is a model, not a measurement. Real failures come in clusters, which is the whole argument for one layer with a deadline rather than more layers.