Railway

Deploy 9Router — Self-Hosted AI Gateway for 60+ Providers

Route Claude Code & Cursor to 60+ LLM providers with fallback

Deploy 9Router — Self-Hosted AI Gateway for 60+ Providers

Just deployed

/data

Deploy and Host 9Router on Railway

9Router is an open-source AI routing gateway — a single OpenAI-compatible endpoint that sits between your coding tools and 60+ LLM providers, automatically falling back across subscription, cheap, and free tiers so a session never dies on a 429. Point Claude Code, Cursor, Cline, Codex, or Copilot at one URL and let the router pick the cheapest available model for each request.

Running it on Railway makes that endpoint reachable from every machine you work on, instead of only the laptop it's installed on.


What This Template Deploys

ServicePurpose
9RouterRouting proxy, web dashboard, and OpenAI-compatible API on port 20128

A single service. 9Router stores all configuration and usage data in SQLite, so a Railway volume mounted at /app/data covers the entire application state — no external database required.


About Hosting 9Router

9Router is normally run locally, bound to localhost:20128. That works well until you use more than one machine: your provider keys, tier configuration, and usage history live on one laptop, and the router is offline whenever that laptop is.

Hosting it on Railway gives you one always-on gateway with a stable HTTPS URL. Your desktop, laptop, and any remote environment point at the same endpoint, share the same fallback configuration, and report into the same usage dashboard.

That convenience has a real security cost, and it's worth being explicit about. A hosted 9Router holds every provider API key and OAuth token you connect to it, behind a single login on a publicly reachable domain. Compromise it and you lose all of them at once. So:

  • Set a long, unique JWT_SECRET and a strong dashboard password before connecting any provider
  • Never reuse a password from elsewhere
  • Treat the instance as a credential store, because that is what it is

9Router itself is fully self-hosted — requests go only to the providers you configure, with no traffic routed through a central service unless you explicitly enable cloud sync.

Typical cost: ~$5/month on Railway's Hobby plan for the single service. 9Router is MIT-licensed and free; you pay providers directly.


How It Compares

9Router (self-hosted)OpenRouterLiteLLM ProxyDirect provider APIs
Cost~$5/mo infra, no markupPer-token markupSelf-hosted, freeProvider pricing
Provider accountsYour ownTheirsYour ownYour own
Free-tier routingYes, automaticNoManual configNo
Token compressionBuilt-inNoNoNo
Usage dashboardBuilt-inYesBasicPer provider
Setup effortLowLowestModeratePer tool

OpenRouter is simpler but adds a markup and routes through their gateway. LiteLLM is more configurable for production API workloads. 9Router is aimed squarely at coding tools, with quota-aware fallback and token savings as the core features.


Deploy in Under 5 Minutes

  1. Click Deploy on Railway and wait for the build (~2 minutes)
  2. Set a strong JWT_SECRET and dashboard password before the service is publicly reachable
  3. Confirm the volume is mounted at /app/data so config and usage history persist
  4. Open your Railway domain, log in, and add provider API keys across the three tiers
  5. Point your coding tool at https://your-domain/v1 instead of the provider's endpoint

Claude Code, Cursor, Cline, Codex, and any OpenAI-compatible client work with a single base-URL change.


Common Use Cases

  • Never hit a rate limit mid-session — automatic fallback to the next available model when a provider returns 429
  • One endpoint for every machine — desktop, laptop, and remote dev environments share one gateway and one config
  • Cut AI coding costs — route to free and cheap tiers first, reserving premium models for what needs them
  • Token savings on large contexts — built-in compression trims tool output that would otherwise eat the prompt budget
  • Unified usage visibility — per-model cost, token count, latency, and success rate across every provider in one dashboard
  • Format translation — use Anthropic, Google, and OpenAI models from tools that only speak one API format

Configuration

VariableRequiredDescription
JWT_SECRETRequiredSigns dashboard and API tokens — use a long random value, never a default
PORTPre-set20128
DATA_DIRPre-set/app/data — must point at the mounted volume
HOSTPre-set0.0.0.0 so Railway can route to the service
DASHBOARD_PASSWORDRequiredLogin for the web dashboard — use a strong, unique value
LOG_LEVELOptionalinfo in production, debug for troubleshooting

Set authentication before you connect providers. This instance stores every API key and OAuth token you add. On a public domain, a weak or default password exposes all of them at once.

The volume at /app/data holds everything. Provider configuration, tier setup, and usage history live in SQLite there. Without it, a redeploy resets the router to a blank state.


Dependencies for 9Router Hosting

  • Railway account — Hobby plan (~$5/month) runs the single service
  • A persistent Railway volume mounted at /app/data (included)
  • API keys or accounts for the providers you want to route to
  • Optional: nothing else — no database, no cache, no external services

Deployment Dependencies

Implementation Details

The template runs the official decocua/9router image on port 20128 with a Railway volume mounted at /app/data. 9Router keeps all configuration and usage analytics in SQLite inside that directory, so one volume covers the full application state and no external database is needed.

The router exposes an OpenAI-compatible API at /v1, which is what makes it a drop-in for tools that already speak that format — changing a base URL is the entire integration. Requests are matched against a three-tier provider configuration and retried against the next available model when one is rate-limited or unavailable.

Because Railway assigns a public HTTPS domain, JWT authentication is not optional here the way it is on a localhost binding. Set JWT_SECRET and a dashboard password before adding provider credentials.

One consideration for OAuth-based providers: callback URLs must point at your Railway domain rather than localhost, so register the Railway URL with the provider when setting those up. API-key providers have no such requirement.


Frequently Asked Questions

How do I point my tools at it? Set the tool's base URL to https://your-railway-domain/v1 instead of the provider's endpoint. Claude Code, Cursor, Cline, Codex, and any OpenAI-compatible client work with that single change.

Is it safe to run this publicly? Only with strong authentication. The instance stores every provider credential you connect, so set a long JWT_SECRET and a strong, unique dashboard password before adding keys. Treat it as a credential store.

Does 9Router see my prompts? Self-hosted, requests go only to the providers you configure — nothing routes through 9Router's own servers unless you explicitly enable cloud sync.

Does my configuration survive a redeploy? Yes, on the mounted volume at /app/data. Provider setup, tier configuration, and usage history all persist there.

How does the fallback work? Providers are organised into tiers. When one returns a rate limit or error, the router automatically retries against the next available model in the tier order you've configured.

Do OAuth providers work when hosted? Yes, but the callback URL must be registered against your Railway domain rather than localhost. API-key providers need no extra setup.

Is it really free? 9Router is MIT-licensed and charges nothing. You pay Railway for infrastructure and your providers directly for usage.

How is this different from OpenRouter? OpenRouter is a hosted gateway that adds a markup and uses their provider accounts. 9Router runs on your infrastructure with your own accounts and no markup, adding free-tier routing and token compression.


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 get an always-on AI gateway with a stable HTTPS endpoint — automatic fallback across 60+ providers, token savings, a unified usage dashboard, and a persistent volume for your configuration. One endpoint for every machine you code on, running on infrastructure you own.


Template Content

More templates in this category

View Template
Chat Chat
Chat Chat, your own unified chat and search to AI platform.

okisdev
113
View Template
stella
Self-host stella with web, API, Postgres, Redis, and object storage.

Jan Kubica
1
View Template
Hermes Agent | OpenClaw Alternative with Dashboard
Self-Hosted Hermes AI Agent for Telegram, Discord & Slack

codestorm
51