Smart Routing: Route every request to the right model.

The routing and fallback setup that keeps an app up is an ordered chain: you name the model, list up to 4 fallbacks, and cap the attempt budget. If the provider fails, the next model in the chain answers, and every response carries headers showing which model served it. nRouter runs this in the gateway, or lets nrouter/auto pick by task fit.

Watch a request find its model.

How routing works. Your model and fallbacks, or nrouter/auto.

Name a model. Only your fallbacks stand in.

Your request goes to the model you chose. Unknown model IDs return 404, never a substitute.

  • Fallbacks come from Router Settings, or nrouter_fallbacks on one call
  • A fallback answers only when the provider cannot take the request
  • You pay the list price of the model that answered
modelclaude-sonnet-5-51stclaude-sonnet-5-5your model2ndgpt-6-lunayour fallbackany other modelnever used503

Or let nrouter/auto pick for you.

Best for the task by default, or Cost-effective, by live list rate. Set it for your org or for one call.

  • Picks only from the models your org, team and key allow
  • Cost-effective orders fit models by input plus output list rate
  • x-nr-model names the model it chose
Best for the taskCost-effectiverequest: "Prove this theorem, step by step."list rateclaude-opus-5-5$$$claude-sonnet-5-5$$gpt-6-luna$x-nr-model: claude-opus-5-5Best for the task matches the model to the prompt

If a provider fails early, the next answers.

Rate limits, overloads and stalls before the first byte move to your next fallback, within 3 calls.

  • Up to 4 fallbacks, per organization or per request
  • No failover once streaming starts, or on 500, 502 or 504
  • One hold, one charge: tries we fail over from cost you $0
first bytebefore: next fallbackafter: no retriesattempt 1claude-sonnet-5-5429attempt 2gpt-6-lunaattempt 2 of up to 3

Every answer tells you how it got there.

x-nr-model names the model that answered, x-nr-routing the path and x-nr-attempts the tries.

  • x-nr-request-cost and x-nr-cost-status show what it cost
  • x-nr-request-id finds the same request in your dashboard Logs
  • The same headers on direct calls and nrouter/auto
HTTP/1.1 200 OKx-nr-model: gpt-6-lunawhich modelx-nr-routing: fallback:1which pathx-nr-attempts: 2how many triesOn every response, so your logs always know.

Two ways to ask for a model.

CapabilityDirect modelYour chosen model first. Only your configured fallbacks next.nrouter/autonRouter picks for each request, from the models you allow.
Who picksYou, by model ID. Unknown IDs return HTTP 404nRouter, from the models your org and key allow
RoutingYour model first, never a model you did not ask forBest for the task, or Cost-effective, by live list rate
FallbacksUp to 4 you list, or none to pin one modelAutomatic, or up to 4 you list (pass [] for none)
BillingOne hold at the served model list rate, 0% platform feeOne hold at the served model list rate, 0% platform fee

Take a closer look. How the SDK works.

  1. 01

    Install

    One package for your language. Python and TypeScript shown; every official SDK works the same way.

    pip install nrouter-sdknpm install @nrouter_ai/sdk
  2. 02

    Create a client

    nRouter() reads NROUTER_API_KEY from your environment and sends each call to api.nrouter.ai. Provider keys are ours to manage.

    client = nRouter()
  3. 03

    Call any model

    The OpenAI-compatible calls you already know. nRouter’s options ride on the same request; each topic below shows one.

    client.chat.completions.create(…)

Already on the OpenAI SDK? Point its base URL at https://api.nrouter.ai/v1 and keep your code.

List up to 4 fallbacks in nrouter_fallbacks. Errors such as 429, 503 and first-byte stalls move down the list before streaming starts, within 3 provider calls by default.

curl -X POST https://api.nrouter.ai/v1/chat/completions \
-H "Authorization: Bearer $NROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6-luna",
"nrouter_fallbacks": ["claude-sonnet-5-5", "gemini-3.1-pro"],
"messages": [{ "role": "user", "content": "Summarize this incident report." }]
}'

Read the docs

FAQs

How does failover work?

Direct mode uses the customer’s own fallbacks: a stalled call fails over inside the same credit hold before the first byte arrives. Only the answering candidate is billed at published list price, while previous failed attempts cost $0.

What happens when a model provider goes down?

When a model provider experiences an outage, rate limit (429), or overload (503), nRouter routes the request to your next configured fallback model within the same credit hold and bills only the model that answers. Failover happens before the first byte; once a stream has started, a provider failure ends that response rather than switching models mid-stream.

What are the two ways to ask for a model?

Direct: you choose the model. nRouter never swaps it for another; a different model answers only through a fallback you configured yourself (a fallback list for that model in Router Settings, or nrouter_fallbacks on the request), and only when the provider cannot take the request. nrouter/auto: nRouter chooses an eligible model for you. Best for the task (the default) uses smart model selection when it is available; Cost-effective orders the models fit for the task by their list rate. Either way you pay the served model’s list price, and x-nr-model names it.

Which model answered my nrouter/auto request?

The response names it. The x-nr-model response header, the model field in the response body and every streamed frame carry the model that served the request; nrouter/auto appears there only when no provider answered. The response also carries the cost, the token counts and the routing outcome: x-nr-request-cost, x-nr-cost-status, the token headers, x-nr-routing and x-nr-attempts.

When does a fallback happen and when does it not?

The gateway moves to the next model in the chain when the provider is rate limited (429) or overloaded (503 or 529), when it rejects with a 401 or 404, when the connection fails, or when an attempt sends nothing before its first-byte time limit and another model is left to try. It does not fail over on a 500, 502 or 504, or once the response has started, because the provider may already have done the work. A fallback list you save for rate limits only, or for errors only, is used only for that kind of failure.

Am I billed twice when a fallback happens?

No. One request holds credit once and settles once, at the price of the model that answered. You are not billed for attempts that failed over.

Who can change routing settings?

The Owner and Organization Admins. Fallback lists and the nrouter/auto preference are edited in Router Settings and apply to the whole organization, not to a single key or team. Members and viewers can read them but cannot change them.

How do I trace a request?

Start with the x-nr-request-id response header. The same response carries x-nr-model, x-nr-routing (direct, or fallback:<n>), x-nr-attempts, the cost headers and the token counts. In the dashboard Logs, the row for that request id shows the model that served it, the cost, and a routing record with attempts, served_rank, fallback_used and source.

How do I choose between Best for the task and Cost-effective?

Set the nrouter/auto preference for your organization in Router Settings, or send nrouter_optimize: "quality" or "cost" on a single request. Best for the task is the default. Cost-effective orders the models fit for the task by list rate: input price plus output price per million tokens, weighted equally. Either way the request is billed at the served model’s list price.

Can I set fallbacks for a single request?

Yes. Add the body field nrouter_fallbacks: an array of up to 4 distinct model ids that does not repeat the requested model. It replaces your organization’s fallback list for that one call. On nrouter/auto it replaces the fallbacks nrouter/auto would choose: its chosen model is tried first, then yours. A request makes at most 3 provider calls by default, so later entries may not be reached. A target you cannot use returns a 400 with the code fallback_not_allowed. On nrouter/auto, a model your organization, team or key denies returns a 403.

Does every model work on every endpoint?

No. A model is served on the endpoint its provider supports. For example, Claude models are served on the Messages endpoint. The model list shows which endpoints each model serves, and a fallback must serve the endpoint you call.

What happens if the model I name is not served?

A name the catalogue does not publish is refused as an unknown model. A direct request is never silently sent to a model you did not choose: only a fallback you configured can answer instead, and only when the provider cannot take the request.

How is nrouter/auto billed?

At the exact list price of the model that served the request, paid from your credits with zero token markup. For existing subscribers, requests draw from their plan allowance first. The x-nr-funding-source response header indicates the source: allowance or credits.

Do safety checks and guardrails still apply to nrouter/auto?

Yes, with one difference. nrouter/auto always runs the built-in checks on prompts and outputs, and every guardrail your organization configured still applies. The platform’s model-scored moderation and prompt-injection checks run when you name a model directly; they are not added to nrouter/auto requests. To have them on nrouter/auto, add them as your own guardrails.

  1. For attempts we fail over from before the first byte, nRouter absorbs any abandoned upstream attempt charge and settles your request once at the answered model list rate. Upfront credit holds are sized to the highest-rate candidate in the chain and refund the difference at settlement.
  2. The 2,000 ms decision deadline on nrouter/auto is the default selection bound (configurable up to 5,000 ms), not a total completion latency guarantee. If the decision step times out or is unavailable, nRouter selects a model tier using local request signals without failing the call. If your organization turns Smart model selection off in Privacy settings, Cost-effective keeps working, and a Best for the task request may be refused with an error that names the setting, before any credit is held.
  3. Callers can list up to 4 fallback models in Router Settings or per request in nrouter_fallbacks; execution walks up to the default 3-call provider attempt budget. Cost-effective mode orders eligible models by live input plus output list price per million tokens weighted equally, which does not predict total output token count.