Skip to content

Retry and cost multipliers

What it looks like

Token use doubles or triples with no rise in traffic. Latency spikes. Logs show the same request sent again and again. Sometimes a user sees one answer, but you paid for five.

Why it happens

A model API does not remember your last request. A retry sends the whole prompt again, and you are billed for those input tokens again. If the first attempt produced some output before it failed, you may pay for that too.

The bigger problem is stacking. Your HTTP client retries. The SDK retries. Your agent framework retries a failed step. Your own code wraps it all in another retry loop. If each layer tries three times, one call can become many. Add "repair" loops, where you re-ask the model to fix bad JSON with the broken output attached, and each attempt gets longer than the last.

Not every error should be retried. A timeout or a rate-limit response may pass if you wait. A request that is too long, or a prompt that keeps producing bad output, will fail the same way every time.

How to spot it

Fix checklist

  1. Retry in one layer only. Turn off or set to zero the retries in the others.
  2. Use exponential backoff with jitter and a hard cap on attempts.
  3. Only retry errors that can pass: timeouts, rate limits, server errors. Never retry a too-long request unchanged.
  4. Use idempotency keys or your own request IDs so repeats do not repeat side effects.
  5. Log attempt count per request and alert on spikes.

Lasting fix

Related on Solaro sites

Next

Cap retries and budget them has copy-paste backoff code in Python and JavaScript.

All failure modes