---
title: "Deploy 9Router (Self-Hosted AI Gateway & Router)"
description: "Self-hosted AI gateway: one OpenAI-compatible API for 60+ LLM providers"
category: "AI/ML"
url: https://railway.com/deploy/9router-self-hosted-ai-gateway-and-route
---

# Deploy 9Router (Self-Hosted AI Gateway & Router)

Self-hosted AI gateway: one OpenAI-compatible API for 60+ LLM providers

**[Deploy 9Router (Self-Hosted AI Gateway & Router) on Railway](https://railway.com/template/9router-self-hosted-ai-gateway-and-route)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/9router-self-hosted-ai-gateway-and-route/manifest.json

- **Creator:** Nick K's Projects
- **Category:** AI/ML
- **Total deploys:** 2

## Template content

### 9Router https://i.imgur.com/yjb5HvR.png

- **Image:** decolua/9router:latest
- **Start command:** `sh -c 'while true; do echo "$(date) - 9Router is active"; sleep 30; done & exec node server.js'`
- **Public domain:** Yes

## Documentation

# Deploy and Host 9Router on Railway

9Router is a self-hosted AI gateway and router. It exposes a single OpenAI-compatible endpoint (`/v1`) in front of 60+ providers — OpenAI, Anthropic, Google Gemini, DeepSeek, Groq, OpenRouter, Ollama and more — with per-key routing, fallbacks, usage tracking and a web dashboard. Point Claude Code, Cursor, Codex, Cline, Continue or any OpenAI SDK at your 9Router URL and switch models without touching your apps.

## About Hosting 9Router

This template deploys the official `decolua/9router` image as a single Next.js service on port 20128 with a persistent volume at `/app/data` for its SQLite database (providers, API keys, routes, request logs). `JWT_SECRET`, `API_KEY_SECRET` and `MACHINE_ID_SALT` are generated per deployment, and `BASE_URL` is wired to your Railway public domain so OAuth-style provider logins and the dashboard work out of the box. Optionally set `INITIAL_PASSWORD` to pre-seed the admin password; otherwise you set it on first visit. The service is lightweight (well under 512 MB RAM at idle) and keeps a heartbeat log so it never sleeps mid-request.

## Common Use Cases

- One API key and one base URL for every LLM provider your team uses
- Route Claude Code / Cursor / Codex through your own gateway with fallbacks and spend visibility
- Mix free-tier and paid providers with automatic failover
- Self-hosted OpenRouter alternative that keeps prompts and keys in your own infrastructure

## Dependencies for 9Router Hosting

- Docker image `decolua/9router:latest`
- A Railway volume at `/app/data`
- Provider API keys (added in the dashboard after deploy)

### Implementation Details

After deploy, open your public domain, set the admin password, add providers and create a 9Router API key. Then in any OpenAI-compatible client:

```bash
export OPENAI_BASE_URL=https:///v1
export OPENAI_API_KEY=
```

For Claude Code use `ANTHROPIC_BASE_URL=https://` with the same key.

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


## Similar templates

- [Chat Chat](https://railway.com/deploy/-WWW5r) — Chat Chat, your own unified chat and search to AI platform.
- [stella](https://railway.com/deploy/stella) — Self-host stella with web, API, Postgres, Redis, and object storage.
- [Hermes Agent | OpenClaw Alternative with Dashboard](https://railway.com/deploy/hermes-agent-or-openclaw-alternative-wit) — Self-Hosted Hermes AI Agent for Telegram, Discord & Slack

Open this page in a browser: https://railway.com/deploy/9router-self-hosted-ai-gateway-and-route
