> ## 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. The package includes `createPiRuntime()`, which calls models through the Pi model catalog with your credentials; you can also connect any SDK with a `RouterExecutor`.

## 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](/router/overview) when Dari should host those concerns.

## Public package boundaries

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

```ts theme={null}
import { createRouter, createPiRuntime, 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`.</Note>

<CardGroup cols={2}>
  <Card title="Quickstart" icon="bolt" href="/framework/quickstart">Run a local router in a few minutes.</Card>
  <Card title="Models" icon="cube" href="/framework/models">Declare Pi or custom candidates.</Card>
  <Card title="Policies" icon="brain" href="/framework/policies">Choose a routing strategy.</Card>
  <Card title="Operations" icon="gear" href="/framework/operations">Handle leases, hooks, and fallback.</Card>
</CardGroup>
