Deploy 9Router Codex

Run Codex CLI through your own router with fallback

Deploy 9Router Codex

Just deployed

/app/data

Deploy and Host self hosted 9Router Codex (Open-Source AI Router) on Railway

This template runs a pinned 9Router container on Railway so the OpenAI Codex CLI talks to your own OpenAI-compatible endpoint at /v1. Requests fall through a combo: subscription first, then cheap, then free. Built for people who run codex exec daily.

About Hosting 9Router Codex open-source software on Railway (self hosted 9Router Codex template)

Your providers, combos, API keys and usage history live in SQLite on a Railway volume at /app/data, not on someone else's router. The dashboard sits at /dashboard, the OpenAI-compatible endpoint at /v1.

Why Deploy 9Router Codex, the OpenRouter alternative on Railway (Railway Free Trial)

You keep the provider accounts, the keys, and the fallback order. OpenRouter is a hosted router where you buy credits; 9Router runs on your Railway service, so combos and usage history stay yours. The $5 trial covers a one-user deploy, and you pay Railway for the box.

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

Railway vs Other Hosting Providers and VPS for 9Router Codex self hosting

Railway hands you a public HTTPS URL for /v1 with no proxy to run; the others hand you a box you configure.

ProviderWhat You Get with RailwayWhat You Get with the Other Provider
DigitalOceanHTTPS domain for /v1, a volume for SQLite state, secrets set in the UI.A Droplet plus your own TLS, proxy and volume mount.
AWSPort 20128, health check on /api/health, persistent data volume.ECS or EC2 with an ALB and EBS, more wiring.
HetznerTemplate deploy, then point Codex at the Railway domain.Cheap VPS, install Docker, add Caddy, back up the SQLite file yourself.

The Codex config is identical either way; only the base URL changes.

Common Use Cases for hosted 9Router Codex

  • Keep coding when a Codex quota resets: your ChatGPT Plus or Pro limit runs out mid-refactor, the combo drops to the next account or a paid fallback model, and codex keeps going instead of dying with a 429.
  • Route routine work to a cheap fallback: put your cx/ subscription model first and a low-cost model second, so small edits and test fixes do not burn quota you need for the hard parts.
  • Share one router across a laptop and CI: both point at the same https://your-domain/v1 with the same 9Router key, so a CI runner gets identical routing without copying your Codex credentials.
  • See per-account usage in one dashboard: round-robin across several accounts and watch quota history per provider, which is far clearer than guessing why one account went quiet.
  • Run codex exec in scripts with the same config: the user-level config.toml applies to non-interactive runs too, so scheduled jobs inherit your model_provider and combo ordering with nothing extra to wire up.

Dependencies for 9Router Codex Docker hosted on Railway

The template is one Railway service running decolua/9router:0.5.95 pinned by digest on port 20128, with health check /api/health and a volume at /app/data for SQLite state and usage. No Postgres or Redis.

Deployment Dependencies for Managed 9Router Codex Service (AI Gateway)

Each deploy generates INITIAL_PASSWORD, JWT_SECRET, API_KEY_SECRET and MACHINE_ID_SALT. Fixed vars: PORT=20128, HOSTNAME=0.0.0.0, DATA_DIR=/app/data, BASE_URL, NEXT_PUBLIC_BASE_URL, CLOUD_URL, AUTH_COOKIE_SECURE=true, ENABLE_REQUEST_LOGS (off by default), REQUIRE_API_KEY=true. HEADROOM_URL and SEARXNG_URL are optional and empty.

Implementation Details for 9Router Codex (Using 9Router official docker image)

State lives in /app/data/db/data.sqlite with backups in /app/data/db/backups. The dashboard is at /dashboard, the OpenAI-compatible API at /v1. Point Codex there with openai_base_url or a custom [model_providers.ninerouter] table, paste a key, and copy an exact model id or cx/ id from the dashboard.

How does 9Router Codex compare against other ways to route OpenAI Codex CLI

Codex only needs a base_url and an env_key, so the real question is what sits behind them.

9Router vs OpenRouter (OpenRouter Alternative)

  • Config: Same three lines in ~/.codex/config.toml; you swap base_url and key.
  • Account model: 9Router uses your own Codex plan and provider keys; OpenRouter uses its credits.
  • Where OpenRouter wins: nothing to host, and one key covers many models without a deploy.

9Router vs LiteLLM (LiteLLM Alternative)

  • Ops: LiteLLM is a Python proxy you install; 9Router is a pinned Docker image with a UI on port 20128.
  • Codex fit: Both expose an OpenAI-compatible /v1, so model_provider and wire_api = "responses" work on both.
  • Where LiteLLM wins: routing as YAML gives teams finer programmatic control than a dashboard.

9Router vs Portkey (Portkey Alternative)

  • Footprint: Portkey is a hosted gateway with an open-source option; 9Router is one container plus SQLite.
  • Data: Providers, keys and usage history stay in your own /app/data volume.
  • Where Portkey wins: managed observability and guardrails if you would rather not run the gateway.

9Router vs direct OpenAI API keys (Direct Codex CLI Alternative)

  • Quota: Direct is one plan or key, so a reset stops the run; combos fall back instead.
  • Config: Direct uses the built-in openai provider; here you set model_provider = "ninerouter" and a cx/ id.
  • Where direct wins: fewer moving parts and one less secret to rotate.

How to use 9Router Codex (the OSS AI router for coding tools)?

  1. Open your Railway domain /dashboard and log in with INITIAL_PASSWORD.
  2. Connect a provider (your Codex subscription or an API-key provider), then build a combo with subscription, cheap and free tiers.
  3. Create an API key and export it:
export NINEROUTER_API_KEY="sk-..."
  1. Add this to ~/.codex/config.toml:
model_provider = "ninerouter"

[model_providers.ninerouter]
base_url = "https://your-domain/v1"
env_key = "NINEROUTER_API_KEY"
wire_api = "responses"
  1. Run codex --model cx/... with an id copied from the dashboard.

The combo falls to the next provider when a Codex quota resets or runs dry, and the request shows up in 9Router usage.

How to self host 9Router Codex on other VPS Services (9Router self hosting guide)

Clone the Repository

Pull the upstream 9Router repository, or skip git and use the pinned image.

docker pull decolua/9router:0.5.95

Install Dependencies

Docker and the compose plugin are enough. Node only matters if you build from source.

Configure Environment Variables

Use your own secrets, not the upstream default password, and mount a volume at /app/data so SQLite state survives restarts.

INITIAL_PASSWORD=change-me
JWT_SECRET=random-string
MACHINE_ID_SALT=another-string
PORT=20128
DATA_DIR=/app/data

Start the 9Router Codex Application

Run the container, open /dashboard, connect Codex, build a combo and copy an API key.

docker run -d -p 20128:20128 --env-file .env -v 9router-data:/app/data decolua/9router:0.5.95

Codex then talks to https://your-domain/v1 once /api/health goes green.

Railway handles the generated secrets, the data volume, the health check and the TLS domain for you.

Official Pricing of 9Router Codex (9Router pricing)

9Router itself is free and MIT licensed, with no per-seat fee and no markup from this template; cloud sync is optional. The cost figure in the 9Router dashboard is tracking only, so check provider billing for the real number.

9Router Codex cloud vs self hosted comparison (Pricing, features, costs, and more)

Cloud sync is optional. Self hosting keeps SQLite state, API keys and Codex usage history on your volume; you still pay the providers behind your combos.

Monthly cost of self hosting 9Router Codex on Railway

One service: decolua/9router on port 20128 with a volume at /app/data. About 512 MB RAM is fine for one Codex user, so Railway usually runs roughly $3-8 per month.

System Requirements for Hosting 9Router Codex on a VPS

A 1 vCPU box with 512 MB to 1 GB RAM is enough, since the router translates and forwards rather than running models. You need Docker, a volume at /app/data for data.sqlite and backups, and port 20128 behind TLS so Codex can reach https://your-domain/v1.

Frequently Asked Questions (FAQs)

Should I use config.toml or environment variables?

Use ~/.codex/config.toml. Set openai_base_url = "https://your-domain/v1" for the built-in openai provider, or a [model_providers.ninerouter] table, and keep only the key in the variable named by env_key.

Which model name do I pass?

Copy the exact id from the 9Router dashboard. Codex subscription models carry a cx/ prefix, and combo names work too. Recheck the list before hardcoding one.

Why do I get a 401?

The key isn't reaching Codex. Export NINEROUTER_API_KEY in the shell you launch codex from, use a key made in the dashboard, and point base_url at /v1.

Can Codex use non-OpenAI models through 9Router?

Yes. The router translates OpenAI, Responses, Claude and Gemini formats, so a Claude provider behind a combo still answers Codex. Keep wire_api = "responses".

Does a project-level .codex/config.toml work for providers?

No. Codex ignores openai_base_url, model_provider and model_providers there and warns you. Keep provider settings in the user-level file.

Where do I see usage?

The 9Router dashboard. You get per-account quota tracking, request logs if ENABLE_REQUEST_LOGS is on, and cost figures that are tracking only.


Template Content

More templates in this category

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

okisdev
117
View Template
NEW
Möbius v0.1 Personal AI OS
Self-hosted AI agent that builds and runs apps for you, with memory.

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

Jan Kubica
7