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

# Operations

> Environment variables, storage, network exposure, data handling, and upgrades for a self-hosted gateway.

## Environment Variables

These configure the gateway process. Provider keys are on [Provider Keys](https://docs.dari.dev/gateway/provider-keys.md).

| Variable | Default | Meaning |
| - | - | - |
| `DARI_GATEWAY_KEYS` | Required | Comma-separated gateway keys. Clients send one as a bearer token. |
| `DARI_GATEWAY_CONFIG` | `dari-gateway.yaml` | Path to the router config. The container image reads `/config/dari-gateway.yaml`. |
| `DARI_GATEWAY_DB` | `dari-gateway.db` | Path to the SQLite database. The container image uses `/data/dari-gateway.db`. |
| `DARI_AUTO_ROUTING_API_KEY` | None | A Dari API key. Enables Dari Auto Routing for `dari/routing`. See [Data Handling](#data-handling). |
| `PORT` | `8080` | Listen port. |
| `DARI_GATEWAY_HOST` | `127.0.0.1` | Listen address. `127.0.0.1` accepts only connections from this machine. The container image sets `0.0.0.0`. |

The [CLI](https://docs.dari.dev/install-cli.md) reads two variables to talk to a gateway instead of Dari's hosted API. Setting `DARI_GATEWAY_URL` switches the launchers and subscription commands to the gateway.

| Variable | Meaning |
| - | - |
| `DARI_GATEWAY_URL` | The gateway's base URL, such as `http://127.0.0.1:8080`. |
| `DARI_GATEWAY_KEY` | One of the gateway's `DARI_GATEWAY_KEYS`. |

## Storage

The gateway keeps a SQLite database at `DARI_GATEWAY_DB`, created with owner-only permissions. It holds:

* **Connected subscriptions.** Access tokens, in plaintext. Back the file up like a secret, and never commit it.
* **Conversation state.** Prefix hashes, conversation ids, serving models, and token counts, so a conversation keeps its model and provider caches warm. Rows older than about an hour are deleted.
* **Session pins.** For routers with `sessionPinning: true`.
* **Saved model lists.** Set with [`dari setup <agent>`](https://docs.dari.dev/gateway/configure-routers#change-models-from-the-cli). They are served in place of the config file's.

Stop the gateway before copying the database, or copy it with `sqlite3 .backup` so the copy is consistent.

## Network Exposure

The gateway serves plain HTTP. It has no TLS and no authentication beyond the gateway keys, so the defaults keep it on this machine.

* **Bare process.** Listens on `127.0.0.1`. Set `DARI_GATEWAY_HOST=0.0.0.0` only on a network you trust.
* **Container.** Listens on all interfaces inside the container. Publish it on loopback with `-p 127.0.0.1:8080:8080`. Docker publishes ports on all host interfaces unless you give an address.

For other machines, put the gateway behind a reverse proxy that terminates TLS. Streams stay open while a model thinks, so give the proxy long or disabled read and idle timeouts for the gateway's routes.

## Rotating Keys

`DARI_GATEWAY_KEYS` accepts several keys, and any one of them authenticates. To rotate without downtime:

1. Add the new key to `DARI_GATEWAY_KEYS`, separated by a comma, and restart.
2. Update each client to the new key.
3. Remove the old key and restart.

## Data Handling

* Provider requests go from the gateway to the providers you configured, under your keys or subscriptions. The gateway sends no telemetry to Dari. Apart from Auto Routing, it makes no calls to Dari's services.
* **Dari Auto Routing** runs only when `DARI_AUTO_ROUTING_API_KEY` is set. Each `dari/routing` request sends the conversation context, up to about 32,000 characters, to Dari's selector at `routing.dari.dev`. The chosen model is then called with your own keys.
* Leave the variable unset to keep conversations off Dari's servers. `dari/routing` then serves the first listed model that has a credential.
* **Zero data retention** is set per router with `zdr: true`. The gateway drops free-text fields, such as routing reasons and selector output, before they reach its database. It also asks providers for zero data retention where they support it. Retention is a provider setting, so confirm each provider's policy before you rely on it.

## Health And Logs

`GET /healthz` returns `{"status":"ok"}` without a key, for load balancers and container health checks.

Logs go to the console. Standard output has the startup summary, a warning for each router with a missing credential, and a summary line with token counts and cost for every routed request. Server errors (5xx) go to standard error.

## Upgrading

Pin the version you run: `bunx @mupt-ai/dari-gateway@<version>`, or a specific image tag. Each release updates the model catalog. Read the release notes first, then check your config against the [Models](https://docs.dari.dev/gateway/models.md) page.


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