A 429 is not a sign that the upstream is broken. In a marketplace it is the normal output of a scheduler that has more requests than slots, and the fix is almost never "retry harder" — it is "retry in a shape the scheduler can absorb".
This note is about the scheduling side of rate limits: why 429s cluster, what Retry-After actually tells you, and how to write a retry loop that does not amplify a mild congestion into a full outage.
Every upstream seller behind a gateway has its own concurrency window: a number of in-flight requests it will accept before it starts shedding load. When your traffic sits well below that window, you see a steady stream of 200s. When it crosses the window, the queue does not degrade gently — it flips. Requests that would have taken 2 seconds start taking 12, then the seller's own timeout fires, then the gateway sees a burst of failures that all look like "too many requests".
That is why one slow endpoint can poison an unrelated one: both are competing for the same concurrency tokens. The practical consequence is that you should treat 429 as a per-seller, per-model signal, not a global one. Log it with the upstream that produced it, not just the model name you asked for.
Most client libraries retry with a fixed schedule and ignore the header. That is the single most common cause of a retry storm: the server tells you "come back in 3 seconds", the client comes back in 200 ms, three times, then escalates. The multiplicand is what turns a 30-second congestion into a 10-minute one.
Retry-After: 3 — wait the whole 3 seconds. Not 2.9, not "3 plus jitter on the first attempt".Retry-After in HTTP-date form — compute the delta against your own clock, and clamp it to a sane maximum so a skewed upstream clock cannot park you for an hour.The loop below is deliberately boring. It caps attempts, honours the header when present, and adds full jitter only when the server gives no guidance. The deadline argument matters more than the attempt count: an interactive request has a budget, and a retry that runs past the caller's budget is just a slower failure.
import random, time, httpx
RETRY_STATUS = {429, 500, 502, 503, 504}
def call_with_budget(client, payload, deadline_s=25.0, max_attempts=4):
start = time.monotonic()
for attempt in range(1, max_attempts + 1):
try:
r = client.post("/v1/chat/completions", json=payload, timeout=20.0)
except (httpx.ConnectError, httpx.ReadTimeout) as exc:
if attempt == max_attempts:
raise
delay = random.uniform(0, min(8.0, 0.5 * 2 ** (attempt - 1)))
else:
if r.status_code not in RETRY_STATUS:
r.raise_for_status()
return r.json()
header = r.headers.get("retry-after")
if header and header.isdigit():
delay = min(float(header), 30.0) # trust the server
else:
delay = random.uniform(0, min(8.0, 0.5 * 2 ** (attempt - 1))) # full jitter
remaining = deadline_s - (time.monotonic() - start)
if remaining <= 1.0 or attempt == max_attempts:
return {"error": "budget_exhausted", "status": r.status_code if 'r' in dir() else None}
time.sleep(min(delay, remaining))
raise RuntimeError("unreachable")
Two details in that loop are easy to miss. First, the sleep is clamped to the remaining budget, so the last attempt never overshoots the caller's deadline. Second, the Retry-After value is capped at 30 seconds: sellers occasionally return a very large value during maintenance, and honouring it literally is worse than failing fast and letting the caller decide.
Retries buy you time; routing buys you throughput. If a model has several sellers behind it, a 429 from one seller should not be retried against the same seller — it should be re-routed. That is the part a client cannot do alone, and it is why the seller count on a listing matters at all: with one seller there is nowhere to route, and the only options are waiting or degrading the request.
On a marketplace where roughly half the listings currently have a single seller, this asymmetry is worth planning for: pick the multi-seller listings for anything latency-sensitive, and put the single-seller ones behind a queue that can absorb a 30-second wait without the caller noticing.
Three numbers, sampled per seller, cover most of it: 429 share as a fraction of total requests, p95 latency, and the retry-to-success ratio. The first tells you whether you are pushing against the window; the second tells you whether you are about to; the third tells you whether your retry policy is helping or hurting. If 429 share rises while p95 latency stays flat, you are being throttled, not congested — different fix, usually concurrency, not backoff.
Live availability per upstream is published on the status page, and the per-model seller counts that decide whether re-routing is even possible are on the model plaza; current prices for the models you are re-routing to are on the pricing page.
Retry-After exactly; only invent jitter when the header is absent.None of this needs a circuit breaker framework. A deadline, a header check, and a jittered cap remove most of the amplification, and the rest is routing.