createGatewayExecutor, or write your own executor for a specific SDK, service, or transport.
Gateway executor
createGatewayExecutor sends each selection to a Dari gateway as a pinned dari/model/<id> request. The router chooses the model; the gateway holds provider credentials and subscriptions and makes the provider call.
fallback.
The executor uses the gateway’s Anthropic Messages wire, so reasoning continuations round-trip and stream in order. Requests that wire cannot express fail with gateway_unrepresentable_request: minimal reasoning effort, json_object response formats (use json_schema), temperatures above 1, system messages after the conversation starts, and provider-hosted tool calls. Requests without an output limit use defaultMaxOutputTokens and fail when it is unset.
Completion executor
RouterRequest, the selected candidate, the validated decision, and an abort signal. A completion can contain text, tool calls, reasoning, and hosted tool calls. Its finish reason is stop, length, or tool_calls.
Streaming executor
Return an async iterable whenrequest.stream is true:
finish, and emit nothing after finish. The full event union is exported as RouterStreamEvent.
Model metadata
Custom models should declare the capabilities they genuinely support:Cancellation and cleanup
Propagatesignal to the SDK. Request cancellation and response-body cancellation abort it. For streams, release resources in finally; Router Core closes an async iterator when a stream ends early.
Fallback
Same-model retries belong to your executor. To retry once on another eligible candidate:requiresDifferentProvider restricts the retry to another provider. The response, hooks, and routing metadata report the model that actually served. A failed primary’s lease is removed. For retry budgets, error classification, or multi-step recovery, own that orchestration outside createRouter.