> ## 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-Host The 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. One endpoint speaks Anthropic Messages, OpenAI Chat Completions, and OpenAI Responses. It serves each request with your provider API keys or your connected Claude Code and ChatGPT subscriptions, and retries the router's next model when a provider fails. It needs no Dari account.

## Run It

The gateway needs [Bun](https://bun.sh) 1.3 or later. From the `dari-gateway` directory:

```bash theme={null}
cp dari-gateway.example.yaml dari-gateway.yaml
export DARI_GATEWAY_KEYS="$(openssl rand -hex 24)"
export ANTHROPIC_API_KEY=... OPENAI_API_KEY=...   # optional with subscriptions
bun install
bun run start
```

| Variable | Meaning |
| - | - |
| `DARI_GATEWAY_KEYS` | Required. Comma-separated keys clients send as `Authorization: Bearer`. |
| `DARI_GATEWAY_CONFIG` | Router config file. Default `dari-gateway.yaml`. |
| `DARI_GATEWAY_DB` | SQLite database for subscriptions and conversation state. Default `dari-gateway.db`. It stores subscription tokens; protect it like a secret. |
| `DARI_AUTO_ROUTING_API_KEY` | Optional. A Dari API key; lets `dari/routing` choose among a router's models with Dari Auto Routing. |
| `PORT` | Listen port. Default `8080`. |

Provider API keys use each provider's standard variable, such as `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, or `OPENROUTER_API_KEY`.

## Configure Routers

```yaml theme={null}
routers:
  default:                 # serves /v1/...
    models:
      - anthropic/claude-sonnet-5-5
      - id: openai/gpt-5.5
        thinking: [medium, high]
    fallback: true         # retry the next model when a provider fails
    subscriptions: true    # prefer connected subscriptions over API keys
  local:                   # serves /local/v1/...
    models: [local/qwen3-coder]

providers:                 # endpoints outside the built-in catalog
  local:
    baseUrl: http://localhost:8000/v1
    apiKeyEnv: LOCAL_API_KEY
```

Send `model: "dari/model/<id>"` to pin one of a router's models, or `model: "dari/routing"` to let the router choose. Without `DARI_AUTO_ROUTING_API_KEY`, `dari/routing` serves the router's first model that has a credential, and falls back down the list on provider failures.

## Connect Subscriptions

Point the [Dari CLI](/install-cli.md) at your gateway and connect plans:

```bash theme={null}
export DARI_GATEWAY_URL=http://localhost:8080
export DARI_GATEWAY_KEY=<one of DARI_GATEWAY_KEYS>

dari credentials subscription connect claude-code
dari credentials subscription connect codex
dari credentials subscription list
```

Connect more than one account per provider to pool them. The gateway stays on one subscription until the provider reports a usage limit, holds it until its reset, then moves to the next. When every subscription for a provider is held, that provider's API key serves if you set one. A Claude Code subscription serves Anthropic models only for Claude Code; a ChatGPT subscription serves OpenAI models for every client.

## Launch Coding Agents

With `DARI_GATEWAY_URL` and `DARI_GATEWAY_KEY` set, the launchers make no calls to Dari's hosted API:

```bash theme={null}
dari claude
dari codex
dari opencode
dari pi
```

Status lines show the serving model, thinking level, and prompt-cache warmth, as they do with the hosted service. `dari router request-costs` and `dari credentials subscription auto-reset` are hosted-only.


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