> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dari.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Auto Router

> Use Dari's hosted selection policy with your own executors.

`createAutoRouter()` is a hosted routing policy. It sends the eligible candidate list and normalized conversation to Dari, receives a decision, and returns it to your local `createRouter`. Your executors still make provider calls and your provider credentials stay in your application.

<Note>You need a Dari API key with billing enabled. Auto Router selection is billed per selection call. For fully hosted routing and execution, use the [Managed Router](/router/overview).</Note>

## Setup

```ts theme={null}
import { createAutoRouter, createPiRuntime, createRouter } from "@mupt-ai/dari-router";

const pi = await createPiRuntime({
  apiKey: ({ provider }) => {
    const key = process.env[`${provider.toUpperCase()}_API_KEY`];
    if (!key) throw new Error(`Missing ${provider.toUpperCase()}_API_KEY`);
    return key;
  },
});

const router = createRouter({
  models: [
    pi.model("openai/gpt-5.6-sol"),
    pi.model("anthropic/claude-sonnet-5"),
  ],
  policy: createAutoRouter({ apiKey: process.env.DARI_API_KEY! }),
  executor: pi,
});
```

Auto Router supplies a default selector endpoint and selector model. You can override the endpoint for testing. `createAutoRouter` does not accept a custom selector, selector runtime, selector model, or custom-rule strategy; those belong to `createDariRoutingPolicy` under `/policy-engine`.

## What leaves your process

The selection request contains the conversation and eligible candidates. It does not contain provider credentials, request metadata, user identity, or encrypted reasoning continuations. Images are represented by an omission placeholder. Readable message content, tool arguments/results, and readable reasoning may be sent to Dari for selection. Review this data flow before enabling it for sensitive traffic.

## Selection leases

A policy may return `leaseTurnsRemaining`. When a request has a `cacheKey` (OpenAI `prompt_cache_key`), `createRouter` stores that lease and serves the same eligible model on subsequent turns without calling the policy. The default store is in memory with a 30-minute TTL. Use a persistent [`leaseStore`](/framework/operations#leases) across replicas.

`router.evaluatePolicy()` never reads or writes leases. `router.select()` and `router.fetch()` do.

## Configuration

```ts theme={null}
createAutoRouter({
  apiKey: process.env.DARI_API_KEY!,
  endpoint: "https://routing.dari.dev/v1/auto-router",
  pricing: (model) => pricing[model] ?? null,
  evals: benchmarkEvals,
});
```

Pricing and output-token averages are optional here because the hosted Dari Auto Router owns its accounting. If you use self-hosted `createDariRoutingPolicy`, you must provide both yourself. The endpoint client posts to `/select` and accepts an endpoint that already ends in `/select`.

## Choosing an approach

Use Auto Router when you want hosted selection but local execution. Use a local `RoutingPolicy` when a deterministic rule is enough or the conversation cannot leave your system. Use [`createDariRoutingPolicy`](/framework/policies) when you want the advanced self-hosted selector pipeline. Use the [Managed Router](/router/overview) when Dari should host the full service.
