Skip to content

Docs / Fallbacks and combos

Fallbacks and combos

Name backup models with models or fallbacks, or save a chain as combo/<name>. What triggers a fallback, what does not, and how it is billed.

Get an API key

A fallback is a backup model. If the first model cannot serve a request, the next one is tried, and you get one answer. You can list fallbacks on each request, or save a chain once and call it by name.

Fallbacks on a request

OpenAI format: models

model is tried first, then each entry in models, in order. Up to 5 entries.

curl https://api.yunshurouter.com/v1/chat/completions \
  -H "Authorization: Bearer $YUNSHU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4-pro",
    "models": ["kimi-k3", "deepseek-v4.1-flash"],
    "messages": [{"role": "user", "content": "Summarise this paragraph: ..."}]
  }'
from openai import OpenAI

client = OpenAI(base_url="https://api.yunshurouter.com/v1", api_key="tq-...")

completion = client.chat.completions.create(
    model="deepseek-v4-pro",
    messages=[{"role": "user", "content": "Summarise this paragraph: ..."}],
    extra_body={"models": ["kimi-k3", "deepseek-v4.1-flash"]},
)
print(completion.model)  # the model that answered
import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://api.yunshurouter.com/v1", apiKey: "tq-..." });

const completion = await client.chat.completions.create({
  model: "deepseek-v4-pro",
  messages: [{ role: "user", content: "Summarise this paragraph: ..." }],
  // @ts-expect-error: Yunshu Router extension
  models: ["kimi-k3", "deepseek-v4.1-flash"],
});
console.log(completion.model);

Anthropic format: fallbacks

A list of objects with a model field. Up to 3 entries.

import anthropic

client = anthropic.Anthropic(base_url="https://api.yunshurouter.com", api_key="tq-...")

message = client.messages.create(
    model="deepseek-v4-pro",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Summarise this paragraph: ..."}],
    extra_body={"fallbacks": [{"model": "kimi-k3"}, {"model": "deepseek-v4.1-flash"}]},
)
print(message.model)
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({ baseURL: "https://api.yunshurouter.com", apiKey: "tq-..." });

const message = await client.messages.create({
  model: "deepseek-v4-pro",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Summarise this paragraph: ..." }],
  // @ts-expect-error: Yunshu Router extension
  fallbacks: [{ model: "kimi-k3" }, { model: "deepseek-v4.1-flash" }],
});
console.log(message.model);

Responses format

/v1/responses does not read models or fallbacks. Use a combo as the model.

When the next model is tried

The first model fails because… Fallback?
It could not be reached, returned an error or timed out (upstream_unavailable, upstream_timeout) Yes
No route can serve it right now (no_route_available, quote_expired) Yes
The model ID is not available (offer_not_found) Yes
The prompt is too long for its context window (context_length_exceeded) Yes, so you can put a longer-context model next
Your key’s allow-list does not include it (offer_not_permitted) It is skipped and the next one is tried
Bad key, empty balance, budget reached, rate limit, invalid request No. Another model would not fix it; you get the error at once

If every model in the chain fails, you get the error from the last model that was tried.

Limits

  • 5 models per chain in total, counting model, combo members and models. Extra entries are ignored. Repeated entries are tried once.
  • Streams fall back only before the first event. After the first event, a failure is reported in the stream. See Streaming.
  • One request against your rate limit, however many models are tried.

Billing

You pay only for the model that answered, at its price. Failed attempts are not charged.

The response’s model field and the x-yunshu-model header name the model that answered. GET /v1/generation shows the same model.

Your balance and key budget are checked before each attempt, at the price of the model being tried.

Combos: saved chains

A combo is a fallback chain saved under a name. Call it as combo/<name> anywhere a model ID goes, on all three formats, including /v1/responses and the Batch API.

curl https://api.yunshurouter.com/v1/chat/completions \
  -H "Authorization: Bearer $YUNSHU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "combo/coding", "messages": [{"role": "user", "content": "Write a unit test for ..."}]}'
  • Create, change and delete combos in the console.
  • Names: 1 to 32 lowercase letters, digits or dashes, starting with a letter or digit.
  • Up to 5 models per combo and 100 combos per organisation.
  • Combos belong to your organisation. Every key in the organisation can call them, subject to each key’s allow-list.
  • GET /v1/models lists your combos, with the models they try in fallbacks and the price of the first one.
  • You can add models to a request that calls a combo; those are tried after the combo’s own models, within the 5-model limit.

With :floor and :nitro

A suffix applies to the model it is written on.

  • In models, each entry keeps its own suffix: "models": ["deepseek-v4.1-flash:nitro"].
  • A combo member keeps the suffix it was saved with. Members saved without one take the suffix on the combo ID, so combo/coding:floor asks for the cheapest route on each of them.