Skip to main content
An executor runs a selected candidate. Run models on a Dari gateway with 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.
Declare only models the gateway router enables. The gateway retries a failing provider call within the pinned model; switching models is the router’s 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

The executor receives the normalized 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 when request.stream is true:
The event sequence must be valid: start tool calls before their deltas, close tools and reasoning before 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:
Capability metadata controls eligibility. It does not add features to your transport; your executor must implement the contract it advertises.

Cancellation and cleanup

Propagate signal 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.