> ## 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.

# Router Framework

> Host one OpenAI- and Anthropic-compatible endpoint across multiple models.

The Dari Router Framework is a small, pre-1.0 TypeScript package for putting several language models behind one web-standard `fetch` handler. You declare models, provide a policy that chooses among eligible candidates, and provide executors that call those models.

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

const policy: RoutingPolicy = ({ candidates }) => ({
  model: candidates[0]!.id,
  reason: "Use the first eligible model.",
});

const router = createRouter({ models, policy, executor });

Bun.serve({ port: 3000, fetch: router.fetch });
```

`models`, `policy`, and `executor` are the three things you supply; `models` is a list of candidate declarations, `executor` is the adapter that calls them, and the Quickstart shows all three together for a complete minimal server.

`router.fetch` accepts OpenAI Chat Completions and Anthropic Messages requests and returns the matching response format. The framework does not host your credentials, persist your conversations, or choose a provider for you.

## The three decisions you make

**Models** are candidate declarations. They describe an ID, reasoning levels, provider metadata, and capabilities such as images, tools, structured output, and streaming.

**Policies** choose one eligible model. A policy can be a local function, a service you own, the self-hosted deterministic policy from `/policy-engine`, or Dari's hosted Auto Router.

**Executors** run the selected model. Implement a `RouterExecutor` to call your provider's SDK or API with credentials your application holds.

## Framework or managed router?

Use this package when your application should own the HTTP endpoint, provider credentials, execution, and operations. Use the [Dari Managed Router](https://docs.dari.dev/router/overview.md) when Dari should host those concerns.

## Public package boundaries

The root package is the end-to-end framework:

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

Advanced deterministic routing is intentionally explicit:

```ts theme={null}
import { prepareRoute, finalizeRoute } from "@mupt-ai/dari-router/policy-engine";
```

Pure protocol adapters and continuation helpers are available from `@mupt-ai/dari-router/protocols`. Most applications should start with `createRouter` and never need either subpath.

> [!NOTE]
>
> Pre-1.0 APIs may change. Do not build compatibility wrappers around removed options such as `createRouter({ runtime: ... })`; the generic router uses `executor`.

> [card] [Quickstart](https://docs.dari.dev/framework/quickstart.md)
>
> Run a local router in a few minutes.

> [card] [Models](https://docs.dari.dev/framework/models.md)
>
> Declare candidates and their executors.

> [card] [Policies](https://docs.dari.dev/framework/policies.md)
>
> Choose a routing strategy.

> [card] [Operations](https://docs.dari.dev/framework/operations.md)
>
> Handle leases, hooks, and fallback.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.