Guide

Fall back to another model when one fails

Every AI provider has outages and rate limits. If your app calls one model at one provider, it goes down with them. A fallback list fixes that inside a single request: when the first model can't answer, the same request goes to the next.

Nicrron does this on its side, so your code makes one call and gets one answer.

Add a fallback list

Keep model as your first choice and list backups in models. Pick backups from different makers, so one company's outage doesn't take out all of them.

Python
import os
from openai import OpenAI

client = OpenAI(base_url="https://api.nicrron.ai/v1", api_key=os.environ["NICRRON_API_KEY"])

reply = client.chat.completions.create(
    model="anthropic/claude-sonnet-5-5",
    messages=[{"role": "user", "content": "Summarise this ticket: ..."}],
    extra_body={"models": ["openai/gpt-6-sol", "deepseek/deepseek-v4-pro"]},
)
print(reply.model)  # which model answered
TypeScript
const reply = await client.chat.completions.create({
  model: "anthropic/claude-sonnet-5-5",
  messages: [{ role: "user", content: "Summarise this ticket: ..." }],
  // @ts-expect-error Nicrron's fallback list isn't in the OpenAI types
  models: ["openai/gpt-6-sol", "deepseek/deepseek-v4-pro"],
});
console.log(reply.model);

How Nicrron tries them

model, then models
Models are tried in order: model first, then each one in models (up to 10), with routing slugs expanded.
Endpoint by endpoint
Within a model, Nicrron tries its endpoints. Unhealthy ones go last.
When it moves on
When a provider rate-limits the request or fails before answering.
Limits
8 models after expansion, 6 endpoint attempts and 90 seconds for something to answer, per request.

If everything in the chain fails, the answer is a 502 whose message says what happened. All the details are in Provider routing and fallback.

Choose providers too

Many models are served by more than one provider. The provider object sets the order (order), limits the choice (only, ignore), sorts by price, latency or throughput, and turns provider fallback off with allow_fallbacks: false.

Python
extra_body={
    "provider": {
        "order": ["anthropic"],   # try this provider first
        "sort": "latency",        # then the fastest healthy ones
    }
}

Or let a routing slug choose

nicrron/auto picks by prompt length, nicrron/reasoning and nicrron/coding lead with strong models for those jobs, nicrron/fastest leads with fast ones and nicrron/cheapest starts from the lowest price. Each expands to a fallback list. See the models docs.

Questions

How do I add a fallback model to an API request?
Send "models": [...] next to "model" in a chat completions request to https://api.nicrron.ai/v1. If the first model can't answer, the same request goes to the next one. With the OpenAI SDK, put models in extra_body (Python) or in the request object (TypeScript).
Which model answered my request?
The answer's model field is the model that actually answered, and provider is who served it. The same request id is in the x-request-id header.
What happens if a stream breaks partway?
Nicrron sends a chunk with an error (code 502) and finish_reason "error". The part already generated is billed. It does not restart the answer on another model, because the first part has already reached you.
Is there a fallback when I don't want to pick models?
Yes. Routing slugs such as nicrron/auto, nicrron/reasoning, nicrron/coding, nicrron/fastest and nicrron/cheapest each expand to a list of models, so they fall back on their own.