skip to content

How does a model gateway decide that one provider target is unhealthy enough to eject from a route, and readmit it without flapping?

level: middleimportance: should knowfreq 48%

answer

  1. judge the target, not the vendor
  2. passive signals from live calls
  3. only failures the target caused
  4. different bars to leave and return
  5. ramp traffic back gradually

basics

~20 s

A gateway ejects a target when live calls show its server-error, overload or slow-first-token rate crossing a bar over enough requests, then readmits it after a cool-off on a small, growing share of traffic against a stricter bar.

solid answer

~50 s

The gateway judges each **target**, one model at one provider, region and account, from **passive signals** on live calls: server errors and overload responses, connection failures, and time to first token compared with that target's own recent baseline. It ignores failures the caller caused, such as malformed requests, and treats a 429 on one API key as a reason to move off that key, not to eject the provider. It ejects only after a minimum number of calls in the window, and never ejects so many targets that a route is left with none. To come back without **flapping**, the target waits out a cool-off that grows with each repeat ejection, then takes a small share of real traffic that rises in steps, and it must beat a stricter bar to return than it needed to stay.

go deeper

for a junior

Recall that the gateway judges each model, region and account separately, and that it learns health from real calls rather than a status page.

for a middle

Explain which signals count, why caller errors and per-key 429s are excluded, and how minimum volume and a slow ramp prevent flapping.

for a senior

Show the guards you would add in production: an ejection cap, cool-offs that lengthen on repeat ejection, latency judged against a per-target baseline.

for a principal

Discuss how aggressive ejection should be per route, trading a few seconds of errors against needless failovers that change which model answers.

## What gets judged: the target, not the vendor A provider rarely fails everywhere at once. An outage usually hits one region, one model or one capacity pool, and a throttle hits one API key or account. So a gateway tracks health per **target**: one model, at one provider or host, in one region, under one account. Ejecting a whole vendor because one region misbehaves throws away healthy capacity at the moment you need it most. **Ejection** means the gateway stops sending a route's new calls to that target for a while. **Flapping** is the failure mode where a target bounces in and out of rotation every few seconds, so callers see a mix of errors and successes and the target never recovers under the load it keeps getting. ## Signals that count, and signals that do not The best signal is what live calls already show: **passive** health. It reacts in seconds and measures exactly the traffic you care about. | Signal | Counts against the target? | Note | |---|---|---| | Server errors and "overloaded" responses | Yes | The core signal | | Connections refused or reset | Yes | Often the first sign of a regional outage | | Time to first token well above its own baseline | Yes | Slow is a failure for interactive routes | | HTTP 429 on one API key | Against that key, not the provider | Move calls to keys with headroom | | HTTP 400 for a malformed request | No | The caller's fault | | Content-policy refusals | No | Correct behaviour, not ill health | **Latency needs care.** Total response time grows with answer length, so a long answer looks "slow" when nothing is wrong. Time to first token is steadier, and comparing it with the same target's recent baseline, ideally per prompt-size bucket, separates a degrading target from a route that simply sends big prompts. **Provider status pages are not the signal.** They are often updated by people after the fact and lag the incident, and they describe a service, not your account or region. Use them to confirm, not to decide. ## Deciding to eject A sound ejection rule has several guards against acting on noise: - **A minimum volume.** Three failures out of four calls on a quiet route is not evidence; require enough calls in the window before judging. - **A rate, not a count.** A failure rate over a sliding window scales with traffic; a fixed count ejects busy targets too eagerly and quiet ones too late. - **A cap on how much of a route may be ejected.** If every target looks unhealthy at once, the problem is more likely the gateway, the network or the request than every provider failing together. Never eject the last target. - **Per-route weighting.** A target that fails one route's long prompts may still serve another route's short ones. ## Coming back without flapping Readmission is where most designs go wrong: the target answers one call and gets full traffic again, which knocks it over again. A calmer sequence: 1. **Cool off.** Keep the target out for a set time, and lengthen it each time the same target is ejected again soon after returning. 2. **Trickle.** Send it a small share of real calls, for example a few percent of the route; prefer low-stakes routes if you can. 3. **Ramp in steps.** Raise its share step by step while it stays healthy, instead of switching from zero to full. 4. **Use a stricter bar to return than to stay.** If a target is ejected above a high error rate, require it to stay well below that rate to come back. That gap, called **hysteresis**, is what stops a target hovering near one threshold from bouncing. ## Where this sits next to circuit breakers Per-target ejection resembles a circuit breaker, and the breaker's state machine and thresholds are covered with circuit breakers in general. What is specific to a model gateway is the unit being judged (model, provider, region and account), which signals count for model calls (time to first token, overload responses, a 429 that belongs to one key) and the rule that ejection only reshapes a route's fallback chain rather than failing calls outright.

  • Why should a 429 on one of your API keys not eject the whole provider?
    A 429 usually says that key, project or account is over its own limit, not that the provider is sick. Other keys or accounts on the same model may have plenty of headroom. The gateway should mark that key as saturated, move calls to targets with remaining quota, and only treat the provider as unhealthy if overload errors appear across keys.
  • Why cap how many of a route's targets can be ejected at once?
    If every target looks unhealthy together, the cause is more likely shared: the gateway, its network path, or a request pattern every model rejects. Ejecting them all turns a partial problem into a total outage for that route. A cap keeps some traffic flowing and makes the shared cause visible.

  • Eject the provider as soon as a single request fails.
  • Wait for the provider's status page before routing around it.
  • Count malformed-request errors toward a target's failure rate.
  • A 429 on one API key means the whole provider is down.
  • Send full traffic back the moment the target answers one call.