Skip to main content
After Router Core filters candidates by capability, your policy picks one.

Write A Policy

A policy receives the normalized request, eligible candidates, and an abort signal:
Policies can be sync or async. They can use a heuristic, benchmark data, a learned model, a remote service, or another LLM. Router Core validates the result against eligible candidates. reasoningEffort is optional — omitting it applies the candidate’s default. The field is reasoningEffort in TypeScript, reasoning_effort in JSON, and thinking_level in Dari custom rules.

Inspect Without Executing

Call router.select() to see a decision without making a provider call:
anthropicRequest(payload) provides the equivalent normalization for Anthropic Messages.

Dari’s Selector Policy

createDariRoutingPolicy() uses a separate LLM call (the selector) to choose the route. Its answer is validated before execution.
selectorModel doesn’t need to be a routed candidate. selectorContextWindowChars is a character budget for the selector prompt, not a token count. Optional callbacks add evidence to the choice:
  • pricing — model and cache rates
  • evals — benchmark scorecards
  • state — observed provider-cache prefixes
  • metadata — richer model capabilities
None are required to run the policy.

Custom Rules Strategy

Use strategy: "custom" to give the selector natural-language rules:
The selector judges each rule’s when text against the request. Its answer must name an eligible pair or Router Core returns a policy error.