Keep Chat Requests Alive: Model Fallback and Provider Routing with models and provider

CQTAI

10/28/2026

#Routing#Reliability#Chat API#Developers
Keep Chat Requests Alive: Model Fallback and Provider Routing with models and provider

Any single model, and any single upstream behind it, can be slow, rate limited or briefly down. If your product sends every request to exactly one place, that is your uptime ceiling.

The chat endpoint gives you two optional fields to raise it. Both follow the shape used by OpenRouter, so code written for that API carries over:

  • models: other models to try if the first one cannot answer.
  • provider: preferences about which upstream provider serves the request.

Neither field is forwarded to the model. The gateway reads them and removes them before the request goes upstream.

models: a fallback list

curl https://api.novapi.ai/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "MODEL_A",
    "models": ["MODEL_B", "MODEL_C"],
    "messages": [{ "role": "user", "content": "Summarize this paragraph in one sentence." }]
  }'

The gateway tries MODEL_A first, then MODEL_B, then MODEL_C. If you leave model out, the first entry of models is the primary.

One thing matters for billing: you are charged for the model that actually answered. A request that falls back to MODEL_B is billed at MODEL_B's price. Pick fallbacks whose price you can live with, and look at your usage records to see which model a request was billed to.

provider: choose the upstream

Some models are served by more than one upstream provider, and the gateway keeps them in a priority order. The provider object lets one request override that order:

{
  "provider": {
    "order": ["provider-x", "provider-y"],
    "only": ["provider-x", "provider-y"],
    "ignore": ["provider-z"],
    "allow_fallbacks": true
  }
}
FieldMeaning
orderTry these providers first, in this order. Others follow unless fallbacks are off.
onlyUse nothing but these providers.
ignoreNever use these providers.
allow_fallbackstrue by default. With false, the gateway tries only what order names, or only the first candidate if you gave no order.

Provider names are codes defined by the platform, such as openai, claude, dashscope or openrouter. Which ones exist for a model depends on how it is served, so ask support if you need the list for a model. A name that matches no upstream of that model simply filters everything out, so copy codes exactly.

The order of attempts

For one request the gateway builds a single ordered list and walks it:

  1. Take the primary model, then each model in models.
  2. For each model, list its providers, apply only and ignore, then put the providers in order first.
  3. Move any provider that has been failing repeatedly to the back of the list. It is demoted, not removed, so if everything is unhealthy the request still tries them all instead of failing at once.
  4. Try each candidate in turn. A failed attempt that could succeed elsewhere moves on to the next one. A chat completion has no side effects upstream, so even a server error is safe to retry on another candidate.

You get the first successful answer, and nothing else is billed.

When to use it

  • A production feature that must not go dark. Name a second model of similar ability in models.
  • A compliance rule. Use only to keep a request on providers you approved, and set allow_fallbacks to false so it never slides onto another one.
  • A flaky upstream you already know about. Use ignore until it recovers.
  • Cost control. Put the cheaper model first and a stronger one as the fallback.

When not to

  • Do not hide quality differences. If MODEL_B answers worse than MODEL_A, your users will see inconsistent output. Log which model answered.
  • Do not use fallback to paper over a bad prompt. A request rejected for an invalid parameter fails the same way on every model.
  • Do not chain five models. Each attempt adds latency. Two or three is plenty.

Check which model answered

The response body carries a model field as reported by the upstream, which normally names the model that ran. Store it next to your request id so a bad answer can be traced to the model that wrote it, and compare it with your usage records when billing matters.

resp = client.chat.completions.create(
    model="MODEL_A",
    messages=[{"role": "user", "content": "Hello"}],
    extra_body={"models": ["MODEL_B"], "provider": {"allow_fallbacks": True}},
)
print(resp.model)

With the OpenAI SDKs, send gateway fields through extra_body (Python) or as additional properties on the request object (TypeScript), because the SDK itself does not know them.

For pricing and key limits that keep fallback from surprising you, see points and cost control.

    Keep Chat Requests Alive: Model Fallback and Provider Routing with models and provider