Deploy 9Router
Self-hosted AI gateway: one API for 40+ model providers, with fallback
9Router
Just deployed
Deploy and Host 9Router on Railway
9Router is a self-hosted AI gateway. It gives Claude Code, Codex, Cursor, Cline, OpenClaw and any other OpenAI- or Anthropic-compatible tool one endpoint, and routes each request to the provider accounts and API keys you connect, falling back to the next one when a quota or rate limit is hit. It also tracks usage and quota, and can shorten tool output to save tokens. This template runs the official 9Router image (0.5.123) on Railway as one service with its data on a volume, a generated dashboard password, and a start script that brings the server back when it is shut down from the dashboard.
This is a community template, not made or supported by the 9Router authors.
About Hosting 9Router
Open your Railway domain and log in with the password in the service's INITIAL_PASSWORD variable (Railway generates it at deploy). Then set your own password under Profile.
Connect providers: under Providers, add the API keys or accounts you want 9Router to use, then build a Combo if you want fallback between several models.
Point your tools at it: create an API key under Endpoint in the dashboard. Your base URL is https://your-domain/v1 (OpenAI format; Anthropic-format tools use the same address). Requests from outside without a valid key are refused, so the address alone gives nobody access to your providers.
The password: INITIAL_PASSWORD only applies until you set your own in the dashboard; after that, changing the variable does nothing. If you forget your password, add the variable RESET_PASSWORD=true and redeploy: the dashboard password becomes INITIAL_PASSWORD again. Remove RESET_PASSWORD afterwards. If INITIAL_PASSWORD is empty, a generated one is used and printed in the deploy logs.
Shutdown and updates: 9Router's dashboard has a Shutdown button. In a container that would end the deployment and leave the service down until you redeploy, so here the server is simply started again a few seconds later. To really stop it, remove the deployment in Railway. 9Router's own "update available" prompt is switched off, because it asks you to run a command on the machine; this template updates when you apply the update Railway offers on the service.
Your data: providers, combos, API keys, settings and usage history are in a SQLite database on the volume at /app/data, with 9Router's own backups beside it, so they survive redeploys. The generated secrets that sign sessions and API keys are kept there too.
Custom domain: after adding one, set BASE_URL to it (for example https://router.example.com) and redeploy.
Provider terms: 9Router can use subscription accounts and free tiers of other services. Whether that is allowed is between you and each provider; read their terms before connecting an account.
Common Use Cases
- One endpoint for a team's or your own coding tools, in front of several provider accounts and API keys
- Automatic fallback to a cheaper or free model when a subscription quota or a rate limit runs out
- Tracking token usage and remaining quota per provider in one dashboard
- Using a tool that only speaks the OpenAI format with a provider that only speaks the Anthropic format, or the other way round
Dependencies for 9Router Hosting
- None to start. You bring the provider accounts or API keys.
Deployment Dependencies
Implementation Details
- Tested on Railway: the healthcheck, logging in with the generated password (and that upstream's default password is refused), setting an own password, creating an API key and listing models with it over the public domain and the private network (both refuse a request without a valid key), the Shutdown call from the dashboard (the server was back in about 4 seconds and the deployment stayed up), keys and settings surviving redeploys,
RESET_PASSWORD, the generated password when the variable is emptied, the notice page with a start-up fault, and a run limited to 0.5 GB. Not tested: real traffic to a model provider (with none connected, a chat request is answered with "No active credentials"), provider logins that use OAuth, the dashboard in a real browser (its pages and scripts load), single sign-on, and the tunnel and cloud-sync features. - Memory: about 65 MB idle in our test, so it runs on a 0.5 GB plan. It grows with traffic: upstream has open reports of the server running out of memory under many concurrent streaming requests, so give it 1 GB or more for anything beyond personal use.
- Stays up: the server runs under a small supervisor. A dashboard shutdown or a crash restarts it in a few seconds without ending the deployment. If it dies right after starting five times in a row, the service shows a notice page that says where to look, instead of restarting in a loop.
- Login attempts: 9Router locks the login for a while after five wrong passwords. Behind Railway's proxy it sees every visitor as the same address, so that lock applies to everyone at once, including you. It clears by itself (30 seconds at first, longer if it keeps happening) or on a restart.
- Secrets: upstream falls back to values published in its source code when
API_KEY_SECRETandMACHINE_ID_SALTare missing. The start script generates both once and keeps them on the volume. You can still set either as a variable; do it before creating API keys. - Image: upstream's
decolua/9router:0.5.123, pinned to the release, plus the start script and a 30-line preload that answers 9Router's own "is there a newer version" lookup with "unknown". Nothing else in the app is changed.
Why Deploy 9Router on Railway?
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying 9Router on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.
Template Content
9Router
two-workspaces/9router
