The gateway is the runtime behind Dari's hosted routing service, packaged to run on your own machine. Point a client at it, and each request is served on the model your router picks, using your provider API keys or your connected Claude Code and ChatGPT subscriptions. It needs no Dari account.
Features
- One endpoint, three protocols.
/v1/messages, /v1/chat/completions, and /v1/responses (plus /v1/models) reach API-key providers in the Pi AI catalog, such as Anthropic, OpenAI, and OpenRouter, or any OpenAI-compatible server.
- Subscription pooling. Connect several Claude Code (Max/Pro) or ChatGPT plans. Each conversation stays on one plan so its prompt cache stays warm. Claude Code plans report their usage on every response: once a plan has used 95% of a window, its conversations move to another plan at their next turn, and new conversations start on the plan whose quota resets soonest. A plan that reports a usage limit is held until its reset, and the request it refused is served by the next plan at once.
- Cross-plan failover. One model can be served by several kinds of plan: GitHub Copilot serves Claude and GPT models, and OpenCode Go and Vercel Token Pass serve the Kimi and GLM models. Each model tries the plans that serve it in a fixed order, the maker's plan first: Claude Code, ChatGPT, Grok, Muse Code, OpenCode Go, GitHub Copilot, Vercel Token Pass, then its provider's API key if you set one. When a plan reaches its usage limit with no other plan of its kind left, or refuses its token, the same request moves to the model's next plan, then to the key, before anything reaches the client.
- 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. Responses carry
X-Dari-Selected-Model, X-Dari-Thinking-Level, and X-Dari-Conversation-Id headers for status lines.
- Coding agents.
dari claude, dari codex, dari opencode, and dari pi from the Dari CLI launch straight against your gateway.
- Activity. Every request's model, tokens, cost, conversation, and tool and skill use is kept in the gateway database and read at
GET /v1/organizations/current/routing/activity/... (overview, series, models, people-keys, conversations, tools-skills, and the rest) with a gateway key, or with dari activity. It is the same code that serves Activity on hosted Dari.
Dari Auto Routing (choosing among a router's models with Dari's trained policy) is optional and needs a Dari API key; without it, dari/routing serves the router's first available model.
Run
[!IMPORTANT]
Activity stays on your gateway. Requests through your own gateway never reach Dari. The gateway keeps their Activity itself, read with dari activity or the Activity API; the Activity dashboard and billing are hosted only (dari gateway setup --mode hosted).
The easiest way to run it on your own machine is the Dari CLI: choose Fully local in dari gateway setup (or on your first dari claude), and it installs this gateway's standalone binary, runs it in the background, and connects your agents.
To run it yourself, use Bun 1.3 or later, or the standalone binary for your platform from the releases. A config file is optional: without DARI_GATEWAY_CONFIG or a dari-gateway.yaml in the working directory, the gateway serves a default router of current Anthropic and OpenAI models, each once its provider has a subscription or API key. To choose models, write a dari-gateway.yaml (start from dari-gateway.example.yaml). Then:
export DARI_GATEWAY_KEYS="$(openssl rand -hex 24)" # keys your clients send
export ANTHROPIC_API_KEY=... OPENAI_API_KEY=... # optional with subscriptions
bunx @mupt-ai/dari-gateway
Or with Docker:
docker run -p 8080:8080 \
-e DARI_GATEWAY_KEYS -e ANTHROPIC_API_KEY \
-v "$PWD/dari-gateway.yaml:/config/dari-gateway.yaml" \
-v dari-gateway-data:/data \
ghcr.io/mupt-ai/dari-gateway
| Variable |
Meaning |
DARI_GATEWAY_KEYS |
Required. Comma-separated bearer keys clients authenticate with. |
DARI_GATEWAY_CONFIG |
Router config file. Default dari-gateway.yaml. |
DARI_GATEWAY_ROUTERS_DIR |
Optional. A directory of router specs, read at startup: each <id>.yaml or <id>.yml is router <id>. |
DARI_GATEWAY_DB |
SQLite database for subscriptions, Dari Link grants, model lists saved with dari setup <agent>, router specs saved through the API, conversation state, and Activity (each request's log row and, outside ZDR routers, its request and response bodies). Default dari-gateway.db. Without DARI_GATEWAY_ENCRYPTION_KEY it stores subscription tokens in plaintext; protect it like a secret either way. |
DARI_GATEWAY_ENCRYPTION_KEY |
Encrypts the subscription tokens, pending sign-ins, and API keys in the database: a 32-byte key in base64 (openssl rand -base64 32). Each value is sealed with AES-256-GCM and bound to its own row, so a copied database, or a token moved into another row, is useless without the key. Keep the key outside the database's storage and backups (a secret manager, not the same disk). To rotate, list the new key first and the old one after a comma, start the gateway once (it re-encrypts everything under the first), then drop the old one. Required for Dari Link: without it the approval page takes nobody's subscriptions or keys. Losing the key loses the stored subscriptions; users connect again. |
DARI_LINK_SESSION_SECRET |
Signs the cookie that remembers the user of Dari Link's approval and connections pages. Unset, each gateway process makes its own, so a restart forgets who connected which plans. Set it on any gateway that serves Dari Link. |
DARI_AUTO_ROUTING_API_KEY |
Optional. Select among a router's models with Dari Auto Routing. |
PORT |
Listen port. Default 8080. |
DARI_GATEWAY_HOST |
Listen address. Default 127.0.0.1, so only this machine can connect. The container image sets 0.0.0.0; set it yourself to expose a process on your network. |
| Provider keys |
Each provider's standard variable, such as ANTHROPIC_API_KEY, OPENAI_API_KEY, META_API_KEY, or OPENROUTER_API_KEY. The gateway checks each key at startup and will not start if a provider rejects one. |
Configure
routers:
default: # serves /v1/...
models:
- anthropic/claude-sonnet-5-5
- id: openai/gpt-6.2-sol
thinking: [medium, high]
agentModels: # optional: a coding agent's own list, in place of `models`
codex: [openai/gpt-6.2-sol, openai/gpt-6.1-terra]
subscriptions: true # prefer connected subscriptions over API keys
sessionPinning: false # route each session and subagent once, then keep its model
nativeCompaction: false # let Codex compact server-side; compacted requests route only to supporting models
roleModels: # optional: serve the main agent or subagents one model, without routing
subagent: openai/gpt-6.2-sol
rolePrompts: # optional: append to the main agent's or subagents' system prompt
main: Delegate codebase exploration to subagents.
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
Model ids are provider/model. Clients send model: "dari/routing" to let the router choose, or model: "dari/model/<id>" to pin one of its models. A Claude Code subscription serves Anthropic models only for Claude Code itself; a ChatGPT subscription serves OpenAI models for every client; other plans serve every client the models they serve (see Cross-plan failover). Each coding agent is offered the router's models that a credential can serve it, or its own agentModels list (claude_code, codex, muse_code, opencode, pi, openclaw, hermes) when the router has one.
dari setup <agent> opens the model picker on a running gateway, with any gateway key. It calls PUT /v1/router/models[/<agent>] (GET reads the lists, DELETE removes a saved one). The gateway saves the list in its database and serves it at once in place of the config file's.
Router specs
A router spec is a whole router as one YAML file with no credentials, the same file hosted Dari applies:
name: Opus 5.5 + DeepSeek Subagents
models:
- anthropic/claude-opus-5-5
- id: deepseek-ai/DeepSeek-V4.1-Flash-1017
thinking: [high]
provider: opencode-go # served by this provider, not the one its id names
roles:
main: { model: anthropic/claude-opus-5-5 }
subagent: { model: deepseek-ai/DeepSeek-V4.1-Flash-1017, prompt: Be brief. }
routing: { session_pinning: false, retries: 1 }
payment: { allow: [subscription, key] } # without subscription, only API keys pay
native_compaction: false
agents: { codex: [openai/gpt-6.1-sol] }