# Self-host 9router

> Router that gives coding tools one OpenAI-compatible endpoint in front of many AI providers, with a web dashboard for provider accounts, fallback combos and usage tracking, storing its state in a SQLite file. Run your own 9router on an always-on EnvHaven workspace by asking its coding agent: one request installs it, puts it on an HTTPS address and locks it down. What the agent takes care of, and the manual route.

_Updated November 23, 2026_

Running your own 9router usually means a list of server chores: a machine that stays on, Docker or a runtime, a reverse proxy with certificates, a domain, and the settings that make 9router behave behind all of it. On an EnvHaven workspace you skip the list. You ask the coding agent, and it does the work while you watch.

## Just ask your agent

Open a Hobby workspace, tap **Launch** to start any coding agent (Claude Code, Codex, OpenCode or another), and ask it:

```text
Set up 9router on this workspace and give me the link. Follow https://envhaven.com/self-host/9router.md
```

Then open the link it sends and create your 9router account straight away, before anyone else finds the address. That is the whole request: the address in it is this page's Markdown copy, and the agent follows the instructions for it further down, with every setting 9router's docs require.

## Or keep it private with Tailscale

The preview URL puts 9router on the public internet, which suits something other people need to reach. For an app only you and your household use, your tailnet is the better home: Tailscale gives 9router an HTTPS address that only your own devices, signed in to your Tailscale account, can open. Save a Tailscale auth key in the workspace's **Vars** pane as `TS_AUTHKEY`, and ask the agent:

```text
Set up 9router on my tailnet instead of the preview URL. Follow https://envhaven.com/self-host/9router.md and https://envhaven.com/guides/self-host-privately-with-tailscale.md
```

- On Plus and Pro, a Tailscale container runs beside 9router, so it keeps its private address through workspace restarts and updates, and every app you set up this way gets an address of its own.
- On Hobby, Tailscale runs in the workspace beside 9router; after a restart or an update, ask the agent to start both again.
- Anything other services have to reach, such as a webhook, still needs a public address. [Keep self-hosted apps private with Tailscale](https://envhaven.com/guides/self-host-privately-with-tailscale) covers both, and what Tailscale's free plan includes.

| At a glance |  |
| --- | --- |
| What it is | AI chat, models and agent tools |
| License | MIT |
| Runs as | Docker (`decolua/9router`) or a native install |
| Memory | Not documented |
| Plan that fits | Hobby or larger |
| Web port | 20128 |
| Documentation | [github.com/decolua/9router/blob/master/README.md](https://github.com/decolua/9router/blob/master/README.md) |

## What your agent takes care of

- **Installing it.** 9router runs from the official image, `decolua/9router`, with its data in folders under `~/apps/9router`, or without Docker on Hobby.
- **Putting it on an HTTPS address.** The workspace's preview URL serves it, and your own domain can too.
- **Locking it down first.** What 9router's docs say to set before it faces the internet, below.
- **Telling you what to back up**: $DATA_DIR/db/data.sqlite (default DATA_DIR is ~/.9router; /app/data in Docker), $DATA_DIR/db/backups/ (automatic backups) and ~/.9router/jwt-secret (auto-generated JWT secret when JWT_SECRET is unset) ([docs](https://github.com/decolua/9router/blob/master/README.md)).

### The settings it needs behind a proxy

- `AUTH_COOKIE_SECURE`: Forces the Secure flag on the dashboard auth cookie; default false, set true behind an HTTPS reverse proxy. ([docs](https://github.com/decolua/9router/blob/master/README.md))
- `BASE_URL` and `NEXT_PUBLIC_BASE_URL`: Documented as the server-side internal base URL used by cloud sync jobs (default http://localhost:20128) and a backward-compatible public base URL; the docs do not say to set them to the public address. ([docs](https://github.com/decolua/9router/blob/master/README.md))
- HOSTNAME and PORT: Bind host and port; the Docker image defaults to 0.0.0.0 and 20128. ([docs](https://github.com/decolua/9router/blob/master/README.md))
- Reverse proxy: The FAQ only says to put an Nginx reverse proxy in front and point tools at https://your-domain.com/v1; no proxy configuration, CORS or WebSocket settings are given. ([docs](https://github.com/decolua/9router/blob/master/gitbook/content/en/faq.md))

### Before it faces the internet

- The first-login dashboard password is 123456 unless INITIAL_PASSWORD is set, so set it before exposing the port. ([docs](https://github.com/decolua/9router/blob/master/README.md))
- Set JWT_SECRET to your own value in production; it signs the dashboard auth cookie and is otherwise auto-generated. ([docs](https://github.com/decolua/9router/blob/master/gitbook/content/en/deployment/cloud.md))
- The /v1 API accepts requests without a Bearer key by default; REQUIRE_API_KEY=true enforces keys and is recommended for internet-exposed deployments. ([docs](https://github.com/decolua/9router/blob/master/README.md))
- API_KEY_SECRET and MACHINE_ID_SALT default to published strings, so set your own values. ([docs](https://github.com/decolua/9router/blob/master/README.md))

## Things to ask next

Everything after the install is one more sentence to the agent. Some that come up:

- "Connect it to the API keys in my Vars pane, and make Claude the default model."
- "Add a second user account for my partner, without admin rights."
- "Move 9router to app.example.com." Add the domain on the dashboard's Domains page with a CNAME to `domains.envhaven.app`, and the agent changes 9router's address settings to match.
- "Update 9router to the latest release." It pulls the new image and recreates the container, data kept.

## Instructions for the agent

The agent reads these from the page's Markdown copy. They also work pasted on their own, if you would rather give them in your own words.

```text
Set up 9router on this workspace and serve it at my preview URL.
- Where Docker has a daemon (Plus and Pro), use Docker Compose with the official image, decolua/9router, starting from the docs' compose file: https://github.com/decolua/9router/blob/master/docker-compose.yml. If `docker compose` is missing, install the Compose plugin into ~/.docker/cli-plugins first.
- Keep the compose file in ~/apps/9router and all of its data in folders there (bind mounts, not named volumes), with restart: unless-stopped on every service.
- This server has no firewall, so publish no port on its public IP, and drop host networking and privileged mode from the docs' compose file. Docker runs on the host: connect this workspace to the compose network and relay my preview URL's port to 9router's port 20128.
- Without Docker (on Hobby, where Docker has no daemon), install it as its docs describe, with `npm install -g 9router`, then `9router` in a terminal (Node.js 20+ (the npm package declares engines node >=20.18.1)), into ~/apps/9router with its data, so it survives workspace updates; global installs and system paths do not. Run it in a tmux window named 9router, listening on 0.0.0.0:20128, and point my preview URL at port 20128.
- The preview URL terminates HTTPS in front of 9router: serve plain HTTP on its port, and trust the forwarded headers the relay passes on.
- Set what "The settings it needs behind a proxy" lists on https://envhaven.com/self-host/9router.md for the preview URL, as 9router's docs describe for running behind a proxy; skip any that apply only when 9router serves HTTPS itself.
- Before the preview URL serves it, apply what "Before it faces the internet" lists on https://envhaven.com/self-host/9router.md.
- When it answers at the preview URL, send me the link and tell me what to back up.
- If I asked for my tailnet instead of the preview URL, set 9router up the same way but follow https://envhaven.com/guides/self-host-privately-with-tailscale.md for the network: no preview URL, no relay.
```

## What to know

- In Docker, 9router's containers keep running when the workspace restarts or updates. The relay from the preview URL is a process in the workspace, so after a restart or an update, ask the agent to restore it.
- Without Docker, 9router runs as a process in the workspace, so after a restart or an update, ask the agent to start it again.
- The production build from source uses a temporary 2 GB swap file in the documented steps, removed afterwards. ([docs](https://github.com/decolua/9router/blob/master/README.md))
- The built-in web-search provider expects a separate SearXNG instance at a local address, so it does not work on a fresh VPS until one is running and SEARXNG_URL points to it. ([docs](https://github.com/decolua/9router/blob/master/README.md))
- A workspace has one preview URL and one custom domain, both serving the same port, so it puts one app on a public address at a time.

## Without a workspace

The manual route, on a server you run:

1. Rent a Linux VPS, secure SSH, and create a user for the app.
2. Install Docker and write a compose file from the official image.
3. Put a reverse proxy in front (Caddy, nginx or Traefik), get certificates, and point a domain at the server.
4. Set the proxy settings listed above for that domain, and pass WebSocket upgrades through the proxy if the app uses them.
5. Keep the firewall closed except for the proxy, and schedule backups and updates.

9router's own [documentation](https://github.com/decolua/9router/blob/master/README.md) covers each step for its install methods.

## Sources

Facts about 9router come from its own documentation, checked on 2026-11-23:

- [github.com/decolua/9router/blob/master/README.md](https://github.com/decolua/9router/blob/master/README.md)
- [github.com/decolua/9router/blob/master/DOCKER.md](https://github.com/decolua/9router/blob/master/DOCKER.md)
- [github.com/decolua/9router/blob/master/gitbook/content/en/faq.md](https://github.com/decolua/9router/blob/master/gitbook/content/en/faq.md)
- [github.com/decolua/9router/blob/master/gitbook/content/en/deployment/cloud.md](https://github.com/decolua/9router/blob/master/gitbook/content/en/deployment/cloud.md)

## Keep reading

- [Self-host any app with your agent](https://envhaven.com/self-host)
- [Self-host Open WebUI](https://envhaven.com/self-host/open-webui)
- [Self-host LibreChat](https://envhaven.com/self-host/librechat)
- [Self-host AnythingLLM](https://envhaven.com/self-host/anythingllm)
- [Self-host Dify](https://envhaven.com/self-host/dify)
- [AI agent hosting](https://envhaven.com/guides/ai-agent-hosting)

Source: https://envhaven.com/self-host/9router
