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

# Run A Gateway

> Host your own Dari Link with the self-hosted gateway.

The [self-hosted gateway](https://docs.dari.dev/gateway/self-hosting) serves Dari Link out of the box: the popup, the tokens, and the model endpoints.

## Required Settings

```bash theme={null}
export DARI_GATEWAY_KEYS=$(openssl rand -hex 24)              # your admin key
export DARI_GATEWAY_ENCRYPTION_KEY=$(openssl rand -base64 32) # encrypts users' logins and keys
export DARI_LINK_SESSION_SECRET=$(openssl rand -hex 32)       # signs the cookie that remembers users
export DARI_GATEWAY_DB=/data/dari-gateway.db
```

> [!WARNING]
>
> Without `DARI_GATEWAY_ENCRYPTION_KEY`, the popup refuses to store anyone's subscription or key. Keep it in a secret manager: lose it and every stored connection is unreadable.

## Rotate The Encryption Key

Put the new key first, keep the old one after it, and restart once:

```bash theme={null}
export DARI_GATEWAY_ENCRYPTION_KEY="$NEW_KEY,$OLD_KEY"
```

On start, the gateway re-encrypts everything with the new key. Then you can drop the old one.

## Allow http Redirects In Development

In `dari-gateway.yaml`:

```yaml theme={null}
link:
  allowHttpRedirectHosts:
    - "*.example.ts.net"
```

## What It Stores

| Stored | Encrypted |
| - | - |
| Users' subscription logins and API keys | Yes (AES-256-GCM) |
| Apps and connections | — |
| Routing state (hashes, model choices, token counts) | — |
| Prompts and responses | **Not stored** |

Users have no Dari account. A signed, HttpOnly cookie remembers what they connected, for a year, and lets them manage it at `/v1/link/connections`.


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