Configure gateway routes
Configure route targets and fallback independently of application inference.
A route moves target selection into Nirmos. You need existing organization-accessible provider/model IDs, working provider credentials and route:create and gateway:execute. Read/update/delete operations need their matching route grants. This workflow creates an active nondefault route with one target and disabled fallback. It leaves workspace default routing unchanged. Replace provider/model IDs with existing catalog IDs.
import type { Requests } from "@nirmos/sdk";
const input: Requests["createRoute"] = {
name: "Support routing",
status: "active",
isDefault: false,
strategy: "weighted",
matchExpression: {
id: "support-condition-group", type: "group", combinator: "and",
children: [{ id: "support-condition", type: "condition",
field: "request.application", operator: "equals", value: "sdk-route-demo" }],
},
targets: [{ providerId: "provider-id", modelId: "model-id", enabled: true, weight: 1 }],
fallback: {
enabled: false,
triggerErrors: [],
maxAttempts: 1,
timeoutMs: 30_000,
targets: [],
},
};
const route = await nirmos.routes.create(input);
if (!route.id) throw new Error("Route creation did not return an ID");
const completion = await nirmos.gateway.chat.create({
route: route.id,
messages: [{ role: "user", content: "Write a short support greeting." }],
});
console.log(completion.outputText);Nondefault route creation requires a nonempty match condition; isDefault: false with matchExpression: null returns HTTP 400, "Add a match condition or mark policy as default." The stored condition currently does not restrict execution: select this route explicitly by ID, as above. Do not rely on it as access control or automatic request matching. Use routing behavior for the supported selection rules.
For a disposable route, call await nirmos.routes.delete(route.id) after inference and after confirming no callers use it. The management response contract contains optional fields, so guard identifiers. Runtime accepts a route ID or configured slug; do not invent a client-side slug creation option when the create DTO does not expose one.
Change configuration
routes.editor(id) returns editor data. routes.update(id, body) requires the complete route payload, including strategy, targets and fallback. Use routes.setStatus(id, { enabled }) for a status change, duplicate(id) for a copy, and reorder({ ids }) for management ordering.
await nirmos.routes.setStatus("route-id", { enabled: false });
const editor = await nirmos.routes.editor("route-id");
console.log(editor);Runtime boundaries
Implemented configured strategies are weighted and round_robin. Runtime filters unavailable/incompatible targets and applies configured fallback. A stored matchExpression does not implement conditional selection. Chat routingStrategy hints are serialized but do not run cheapest/fastest/quality optimization algorithms.
SDK transport retries and runtime provider retries/fallback are different layers. An ordinary chat POST has no automatic SDK retry. See routing and fallback, route reference and REST routes.
Validation can reject incomplete route payloads; inference can reject a disabled route or incompatible targets. Inspect error code/status/request ID.