The promise of a gateway key is that you stop thinking about upstreams: one base URL, one key, and the model name you already have in your client. That holds right up to the moment one seller stops answering. Then the interesting question appears — failover is not "retry the same request", it is "decide whether a different seller can take this request, and what it costs to find out".
The marketplace shape behind the key is uneven by design. In the current public snapshot there are 109 live entries, and 58 of them have exactly one seller behind them; 16 have two, and the rest spread across three or more, with the widest entry reaching 15. Certification is uneven too: 193 certified sellers sit across 106 entries, and 3 entries have no certified seller at all. Failover quality is a property of that distribution, not of the gateway software.
The key maps to a (model, seller) pair at request time, and the mapping is re-decided on every call unless you pin it. Three consequences follow:
The seller-count distribution per model is on the model plaza; the model reference pages that document units and tiers are on docs.
Most "failover" bugs come from treating every error as retryable. The distinction that matters is whether the request was rejected before or after the upstream started work.
| Failure | What it means | Right action |
|---|---|---|
| 429 with Retry-After | the seller is congested but healthy | wait the header value on the same seller, or re-route if the deadline is tight |
| 5xx / timeout mid-stream | the seller started work and gave up | re-route, but treat the partial output as wasted billing |
| 401 / 403 on a pinned pair | credentials or quota on that seller changed | do not retry; unpin and pick another seller |
| connection refused / DNS | the seller is gone from the pool | re-route immediately, log the seller out |
The mid-stream case is the expensive one: tokens were already generated, so a retry re-bills the same prompt and pays twice for the failed half. That is why the retry budget should be denominated in money or tokens, not attempts.
A retry loop that walks the same seller is amplification. A failover path changes the target and keeps the budget. Three rules keep it cheap:
The snippet below keeps the deadline and the token budget outside the loop, and only re-routes on errors that are worth re-routing. It runs against any OpenAI-compatible endpoint, so it can be tested without a gateway.
import httpx, time
REROUTE_ON = {429, 500, 502, 503, 504}
def call_with_failover(client, payload, deadline_s=25.0):
t0 = time.monotonic()
for seller in ["a", "b"]: # at most two hops
if time.monotonic() - t0 > deadline_s:
break
try:
r = client.post("/v1/chat/completions", json=payload,
headers={"X-Seller": seller}, timeout=deadline_s)
except (httpx.ConnectError, httpx.ReadTimeout):
continue # seller unreachable, next hop
if r.status_code not in REROUTE_ON:
r.raise_for_status()
return r.json()
retry_after = r.headers.get("Retry-After")
wait = min(float(retry_after or 2), 8.0)
if time.monotonic() - t0 + wait > deadline_s:
raise RuntimeError("deadline exceeded before hop 2")
time.sleep(wait)
raise RuntimeError("no seller answered inside the deadline")
Two details make it useful rather than illustrative: the deadline is checked before every hop, and the wait is capped so a bad Retry-After cannot consume the whole budget. The seller header is a stand-in for whatever routing hint your gateway accepts; the point is that the target changes while the budget does not.
Failover only pays off if you can tell whether it worked. Three numbers answer that: the share of requests that needed a second hop, the p95 latency of second-hop requests versus first-hop ones, and the fraction of re-routes that ended in success. A rising second-hop share with a falling success rate means the pool is degrading and failover is hiding it.
The per-upstream view is on the status page; the definitions used for 429 share and retry success are in the FAQ.
The short version: pin when you need determinism, do not when you need price, and always measure how often you needed the second hop — because that number is the real quality of the pool you are buying from.