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

# Self-Hosted Gateway

> Run the open-source Dari Gateway on your own machine and point coding agents at it.

Dari Gateway is the open-source runtime behind Dari's hosted routing service, packaged to run on your own machine. Point a client at it and each request is served by a model from your router, using your provider API keys or your connected Claude Code, ChatGPT, or Muse Code subscriptions. It needs no Dari account.

## What It Does

* **One endpoint, three protocols.** Anthropic Messages, OpenAI Chat Completions, and OpenAI Responses share one server, along with a model list.
* **Routers.** Each router is a named set of models and settings, served on its own path.
* **Your credentials.** Serve from provider API keys, connected subscriptions, or both. Several subscriptions per provider are pooled.
* **Failover.** A provider failure retries the router's next model.
* **Prompt-cache aware.** Conversations keep their identity and serving model across turns, so provider caches stay warm.

## How A Request Is Served

1. **Authenticate.** The client sends one of your gateway keys (`DARI_GATEWAY_KEYS`) as a bearer token.
2. **Pick the router.** `/v1/...` uses the `default` router. `/<router>/v1/...` uses the router with that name.
3. **Pick the model.** `dari/model/<id>` serves exactly that model. `dari/routing` lets the router choose: with `DARI_AUTO_ROUTING_API_KEY` set, Dari Auto Routing picks, and without it the first model in the list that has a credential serves.
4. **Pick the credential.** With `subscriptions: true`, a connected subscription serves first. Otherwise, or when every subscription is held, the provider's API key serves.
5. **Call the provider.** A failed call retries the same model up to `retries` times, then moves to the next model.

## Hosted Or Self-Hosted

> [!NOTE]
>
> **Observability needs hosted Dari.** Requests served by a self-hosted gateway never reach Dari, so there is no Activity dashboard, per-request cost, or usage analytics for them. If you need those, use hosted routing.

| | Hosted routing | Self-hosted gateway |
| - | - | - |
| Account | Dari account | None |
| Provider keys and plans | Saved in Dari | Your environment variables and gateway database |
| Router configuration | Dashboard and CLI | `dari-gateway.yaml` |
| Model selection | Dari routing policy, on your plan | First-listed model, or Dari Auto Routing with a Dari API key |
| Activity, request costs, usage analytics | Yes | No |
| Coding agent launchers | `dari claude`, `dari codex`, and others | Same launchers, pointed at your gateway |

## Start Here

> [card] [Quickstart](https://docs.dari.dev/gateway/quickstart.md)
>
> Run the gateway and send it a first request.

> [card] [Configure Routers](https://docs.dari.dev/gateway/configure-routers.md)
>
> Choose the models and settings each router serves.

> [card] [Subscriptions](https://docs.dari.dev/gateway/subscriptions.md)
>
> Connect and pool Claude Code, ChatGPT, and Muse Code plans.

> [card] [Coding Agents](https://docs.dari.dev/gateway/coding-agents.md)
>
> Launch Claude Code, Codex, and other agents against the gateway.

The source is in [`packages/gateway`](https://github.com/mupt-ai/dari/tree/main/packages/gateway) of [github.com/mupt-ai/dari](https://github.com/mupt-ai/dari), under Apache-2.0.


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