---
title: "Deploy Unorouter"
description: "Self-hosted AI gateway + storefront. One key for 100+ AI providers."
category: "AI/ML"
url: https://railway.com/deploy/unorouter
---

# Deploy Unorouter

Self-hosted AI gateway + storefront. One key for 100+ AI providers.

**[Deploy Unorouter on Railway](https://railway.com/template/unorouter)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/unorouter/manifest.json

- **Creator:** mcmax
- **Category:** AI/ML
- **Total deploys:** 1

## Template content

### storefront

- **Image:** ghcr.io/unorouter/unorouter:latest
- **Health check:** /api/ops/health
- **Public domain:** Yes

### gateway

- **Image:** ghcr.io/unorouter/new-api:latest
- **Health check:** /api/status
- **Public domain:** Yes

## Documentation

# UnoRouter

Self-hosted AI gateway + front-end. One OpenAI-compatible key that routes to 100+ upstream providers, with a full Next.js dashboard, chat client, model catalog, price comparison, usage-based billing, and public status page.

Two services: `gateway` (the UnoRouter gateway, a new-api fork) + `storefront` (Next.js front-end).

## Deploy and Host

Host your own UnoRouter on Railway. The template provisions both services from prebuilt images, wires the storefront to the gateway over Railway's private network, and mounts persistent volumes for both services.

[![Deploy on Railway](https://railway.app/button.svg)](https://railway.com/deploy/unorouter)

## Why Deploy

- **One key, 130+ providers** — route OpenAI-, Claude- and Gemini-compatible requests through a single gateway with channels, retries and fallbacks.
- **Full dashboard** — API keys, usage logs, billing, credits, affiliate and gift cards out of the box.
- **Same-origin proxy** — the storefront's server routes proxy dashboard, model and billing calls to the gateway over Railway's private network, so the gateway is never exposed publicly and no gateway token reaches the browser.
- **Model tester + rankings** — probe any endpoint with nonce-tagged prompts to verify the model behind it, with a public leaderboard persisted in SQLite.
- **Per-device chat state** — chat, characters and presets live in the visitor's browser (SQLocal/OPFS); nothing to migrate.

## Common Use Cases

- Teams that want a single metered AI key across many upstream providers.
- Self-hosters who want a private OpenAI-compatible endpoint with a real dashboard.
- Communities running a shared chat client with their own branding and pricing.

### Deployment Dependencies

- Both services come from prebuilt images (`ghcr.io/unorouter/new-api`, `ghcr.io/unorouter/unorouter`) — no build step, deploys in under a minute.
- The gateway keeps its SQLite DB on the `gateway-data` volume at `/data`.
- The storefront keeps its rankings DB on the `storefront-data` volume at `/data`; chat state is per-device in the browser.
- The storefront reaches the gateway via `${{gateway.RAILWAY_PRIVATE_DOMAIN}}` — nothing to type.

## Architecture

```
            ┌─────────────┐   private network    ┌─────────────┐
  browser ─▶│  storefront │ ────────────────────▶│   gateway   │──▶ 100+ upstream providers
            │  (Next.js)  │   http://gateway:    │ (new-api)   │
            └─────────────│   ...:3000           └─────────────┘
                          │ /api/* BFF proxy injects the gateway key
```

- `gateway` — UnoRouter gateway (new-api fork): model routing, channels, API keys, billing, usage logs, and a relay speaking OpenAI-, Claude- and Gemini-compatible formats. Serves its own admin UI at `/`.
- `storefront` — Next.js front-end: dashboard, chat client, model catalog, price comparison, status page. Server routes act as a backend-for-frontend and proxy to the gateway over the private network.

## Features

- Multi-provider routing with channels, groups, retries and fallbacks
- OpenAI / Anthropic / Gemini-compatible relay endpoints
- API key management, quotas, billing, credits, gift cards
- Usage logs and analytics with per-key granularity
- Model catalog with price comparison and a public model-tester leaderboard
- Roleplay-grade chat client: characters, lorebooks, presets, plugins, group chats
- 18 UI locales

## Dependencies for

- **gateway**: SQLite (bundled, on volume) or an external MySQL/PostgreSQL via `SQL_DSN`; optional Redis via `REDIS_CONN_STRING` for multi-node caching.
- **storefront**: reaches the gateway over Railway's private network via `INTERNAL_API_URL`; persists rankings in SQLite on the volume via `TURSO_DATABASE_URL`.

## About Hosting

- **Volumes**: gateway `/data` (SQLite DB, channel config, usage logs), storefront `/data` (rankings DB). Railway volumes mount root-owned; both images are configured so a fresh install boots cleanly.
- **Private networking**: `INTERNAL_API_URL` resolves to `http://:3000` at deploy time. The gateway is never publicly exposed unless you add a public domain to it.
- **First run**: create the admin account at the gateway's public URL (the dashboard is served by the gateway itself; first user becomes root with password `123456` — change it immediately after first login).

## Configuration

| Variable | Service | Default | Description |
|---|---|---|---|
| `SESSION_SECRET` | gateway | auto (`${{secret(48)}}`) | Signs gateway sessions and OAuth state. |
| `FRONTEND_BASE_URL` | gateway | auto (`${{RAILWAY_PUBLIC_DOMAIN}}`) | Absolute base for callback/share URLs. |
| `TZ` | gateway | `UTC` | Timezone for usage-log timestamps. |
| `SQL_DSN` | gateway | *(empty → SQLite)* | Optional external MySQL/PostgreSQL. |
| `REDIS_CONN_STRING` | gateway | *(empty → memory)* | Optional Redis for multi-node caching. |
| `SESSION_SECRET` | storefront | auto (`${{secret(48)}}`) | Seals storefront session cookies (min 32 chars). |
| `NEXT_PUBLIC_URL` | storefront | auto (`${{RAILWAY_PUBLIC_DOMAIN}}`) | Public origin for links, canonical URLs, cookie scope. |
| `NEXT_PUBLIC_API_URL` | storefront | auto (`${{RAILWAY_PUBLIC_DOMAIN}}`) | Origin shown in API docs / direct browser calls. |
| `NEXT_PUBLIC_APP_NAME` | storefront | `UnoRouter` | Brand name in header, titles, SEO. |
| `NEXT_PUBLIC_SUPPORT_EMAIL` | storefront | `support@example.com` | Support contact in help links. |
| `NEXT_PUBLIC_CARDS_URL` | storefront | auto | Gift-card store origin. |
| `INTERNAL_API_URL` | storefront | auto (`${{gateway.RAILWAY_PRIVATE_DOMAIN}}`) | Gateway private-domain proxy target. |
| `TURSO_DATABASE_URL` | storefront | `file:/data/storefront.db` | Rankings SQLite file on the volume. |
| `RAILWAY_RUN_UID` | storefront | `0` | Distroless nonroot image + root-owned volume: must run as root. |

Health checks: gateway `GET /api/status` (200 on a fresh install before any account exists), storefront `GET /api/ops/health` (reports `db` + `upstream` checks).

## Quick Start

1. Click **Deploy on Railway** — the form pre-fills every variable (secrets auto-generate, cross-service refs auto-wire).
2. Wait for both services to turn green (healthchecks: `/api/status`, `/api/ops/health`).
3. Open the **gateway** domain → log in with `root` / `123456` → change the password immediately (Users → root → edit).
4. Add a channel in the gateway (Channels → add: pick a provider, paste its API key, choose models).
5. Create an API key (Tokens → add token) and start proxying: `curl /v1/chat/completions -H "Authorization: Bearer " ...`
6. Open the **storefront** domain → the dashboard, model catalog and chat client are live. Chat runs per-device in the browser and proxies through the storefront's `/api/*` routes; log in to the dashboard to create keys without leaving the storefront.

## License

UnoRouter storefront: AGPL-3.0. Gateway (new-api): Apache-2.0. This template's glue files: MIT.

## 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/unorouter
