Nirmos
Gateway

Routing and fallback

Select inference targets and understand when runtime fallback can occur.

The SDK serializes target selection; routing runs in Nirmos runtime. Choose exactly one target:

await nirmos.gateway.chat.create({
  model: "configured/chat-model",
  messages: [{ role: "user", content: "Hello" }],
});
await nirmos.gateway.chat.create({
  route: "production-chat",
  messages: [{ role: "user", content: "Hello" }],
});

A physical model uses a provider-qualified identifier. Unqualified names can be ambiguous. A route accepts an enabled active ID or slug; model: "nirmos/<route-slug>" also addresses a virtual route. The SDK does not use a default route when both fields are omitted.

Model names beginning with configured/ are placeholders. Replace them with an accessible provider-qualified identifier from model discovery. The snippets reuse the server client from the quickstart.

Implemented route strategies

StrategyRuntime behavior
weightedChoose eligible enabled targets using positive weights
round_robinAdvance across eligible targets within the gateway process

Availability and capabilities restrict candidates. Configured fallback defines targets, trigger errors, attempts and timeout. It applies only after target resolution and eligible execution failures, not to every HTTP failure. Nirmos authentication/authorization failures and invalid route configuration do not become fallback inference. See route setup for the complete management payload.

Direct-model fallbacks

await nirmos.gateway.chat.create({
  model: "configured/primary-model",
  fallbackModels: ["configured/backup-model"],
  messages: [{ role: "user", content: "Summarize this incident." }],
});

Both models must be enabled and support the requested capabilities. Fallback runs server-side and differs from SDK HTTP retries. Embeddings reject routes and cross-model fallback.

Hints and limits

routingStrategy accepts known and extensible strings; highestQuality maps to highest_quality on the wire. Current runtime does not implement cheapest/fastest/highest-quality optimization based on these hints. Stored matchExpression/request metadata do not run conditional routing trees.

Routes reference · Gateway reference · REST routes · Reliability

Upstream gateway routing boundary

OpenRouter remains one upstream in Nirmos routes. Its same-model host routing is configurable through providerOptions.openrouter.provider; Vercel host preferences use providerOptions.vercel.providerOptions.gateway.order and sort. Nirmos retains cross-model fallback. Provider-scoped options never reach another upstream during fallback. Upstream models arrays are rejected. See provider controls.

Failure categories and streaming

Configured routes use their triggerErrors list. Recognized categories are timeout, rate_limited, provider_unavailable, provider_error, connection_error, authentication_error, invalid_request, context_length_exceeded and content_blocked. These describe classified upstream execution failures. A caller's invalid Nirmos API key fails before provider execution.

The runtime checks the configured attempt limit and available fallback targets. Same-target retries may occur before switching targets. Caller cancellation stops fallback. Streaming can switch only before any chunk has been emitted; output is never spliced from multiple attempts.

Direct-model fallbackModels uses the runtime's direct-model failure list, rather than route-specific trigger selection. Use a configured route when you need explicit trigger control. The fallback recipe separates provisioning from application calls.

On this page