LLM API Retry and Fallback Patterns That Don't Double Your Bill
A retry on a metered LLM API is a second request, and sometimes a second bill. This guide sets an attempt budget, classifies errors, and adds a cheap standby model on AtmoRouter's OpenAI-compatible endpoint. AtmoRouter-authored; all cost figures are illustrative arithmetic.
Why it matters
The part most retry guides skip: a retried chat completion is not free. A request rejected before any tokens were generated costs nothing, and AtmoRouter does not bill failed requests. A client timeout that fired after generation started does cost money, and retrying it pays twice for one answer.
The fix is one retry layer with a wall-clock deadline instead of a bare attempt count. The OpenAI Python SDK already retries rate limits, server errors and connection failures twice by default, so wrapping your own loop around it multiplies requests: set max_retries to zero and own the budget in one place. Then branch on the SDK error classes, honour Retry-After and add jitter.
Then add a standby model rather than a second attempt at the same overloaded one. Swapping the model field is the whole change, and catalogue from-prices make a cheap standby boring: zai/glm-5.3 at from $0.0035 / $0.011 per million tokens against cx/gpt-6-sol at from $0.1 / $0.5. Rates move; the model page is authoritative.