9Router: Connect Claude Code, Codex, and Cursor to One AI Router

A practical overview of 9Router: a local AI router for Claude Code, Codex, Cursor, Cline, and other coding tools, with token compression, model fallback, and multi-account routing.

9Router is a local router for AI coding tools. It lets Claude Code, Codex, Cursor, Cline, Copilot, OpenCode, OpenClaw, and similar tools connect to one OpenAI-compatible endpoint, then routes requests to different models and providers.

It is not trying to be another chat client. It sits between your AI coding tools and model providers, solving a few practical problems: incompatible API formats, manual provider switching, fast token burn from tool output, interrupted work when quotas run out, and messy multi-account configuration.

According to the project README, 9Router supports 40+ providers and 100+ models. It includes RTK Token Saver, automatic fallback, quota tracking, multi-account rotation, format translation, and request logging. The project is written in JavaScript and uses Node.js, Next.js, React, Tailwind CSS, and LowDB. It is licensed under MIT.

What It Is Good For

9Router is most useful when you use multiple AI coding tools and multiple model sources at the same time.

Examples:

  • Claude Code uses a subscription account.
  • Codex or Cursor needs a custom OpenAI endpoint.
  • Cline, Continue, or RooCode needs an OpenAI-compatible API.
  • Free providers are used for experiments.
  • GLM, MiniMax, or Kimi is used as a cheaper backup.
  • High-quality models are reserved for difficult tasks.

Without 9Router, these settings are scattered across many tools. Each tool needs its own endpoint, API key, model name, and fallback plan. 9Router centralizes that into one local routing layer.

Default local API:

1
http://localhost:20128/v1

Dashboard:

1
http://localhost:20128/dashboard

Quick Install

For local use, npm is the simplest path:

1
2
npm install -g 9router
9router

The dashboard opens locally, and the README uses 20128 as the default port.

Run from source:

1
2
3
4
5
git clone https://github.com/decolua/9router.git
cd 9router
cp .env.example .env
npm install
PORT=20128 NEXT_PUBLIC_BASE_URL=http://localhost:20128 npm run dev

Production mode:

1
2
npm run build
PORT=20128 HOSTNAME=0.0.0.0 NEXT_PUBLIC_BASE_URL=http://localhost:20128 npm run start

The npm package requires Node.js >=18.0.0. For VPS or Docker deployment, configure JWT_SECRET, INITIAL_PASSWORD, DATA_DIR, and API_KEY_SECRET instead of exposing defaults.

Connect Coding Tools

9Router exposes an OpenAI-compatible API, so most tools that support custom OpenAI endpoints can connect to it.

Typical configuration:

1
2
3
Base URL: http://localhost:20128/v1
API Key: copied from the 9Router dashboard
Model: a model name or combo name configured in 9Router

For Codex CLI:

1
2
3
4
export OPENAI_BASE_URL="http://localhost:20128"
export OPENAI_API_KEY="your-9router-api-key"

codex "your prompt"

For Cline, Continue, or RooCode, choose OpenAI Compatible and set:

1
2
3
Base URL: http://localhost:20128/v1
API Key: your-9router-api-key
Model: cc/claude-opus-4-7

Model names depend on connected providers. The README shows prefixes such as cc/, cx/, gh/, glm/, minimax/, kr/, and vertex/.

RTK Token Saver

AI coding tools often burn tokens fastest on tool outputs:

  • git diff
  • git status
  • grep
  • find
  • ls
  • tree
  • logs
  • long file lists

9Router includes RTK Token Saver, which compresses these outputs before they are sent to the model. The project says this can save 20%-40% input tokens in many requests.

The value is that you do not need to change tools or models. The routing layer removes waste before the request reaches the provider. Still, for critical logs or complete file content, test the behavior first and make sure answer quality does not drop.

Automatic Fallback

9Router can arrange models in priority order:

1
2
3
1. Subscription model
2. Cheap API
3. Free provider

When the first tier is rate-limited, out of quota, or failing, it can switch to the next one. This reduces manual switching and keeps coding sessions from stopping suddenly.

Example:

1
2
3
1. cc/claude-opus-4-7
2. glm/glm-5.1
3. kr/claude-sonnet-4.5

Fallback changes output consistency. Different models have different style and reasoning quality. For large refactors, protocols, migrations, or other consistency-sensitive work, prefer a fixed model and switch manually only when needed.

Be Careful with Free Providers

The README highlights Kiro, OpenCode Free, Vertex, and also notes that some old free tiers have changed or are no longer recommended.

Always confirm provider policy at the time of use:

  • Is it really free?
  • Is it region-limited?
  • Is third-party tool access allowed?
  • Can it trigger bans or rate limits?
  • Does the free quota expire?

9Router manages routing, not upstream terms. Be especially careful when using personal subscriptions, OAuth tokens, or free quotas with automated tools.

Local Deployment Advice

For personal use, bind to localhost. Local tools can reach it, but the internet cannot.

For VPS or LAN deployment:

  • Change the default login password.
  • Set a strong JWT_SECRET.
  • Set API_KEY_SECRET.
  • Put authentication in front of the dashboard.
  • Do not expose the dashboard directly to the public internet.
  • Require Bearer API keys for /v1/*.
  • Back up DATA_DIR.

Docker example:

1
2
3
4
5
6
7
docker run -d \
  --name 9router \
  -p 20128:20128 \
  --env-file ./.env \
  -v 9router-data:/app/data \
  -v 9router-usage:/root/.9router \
  9router

Start locally first, verify providers, combos, logs, and model names, then decide whether server deployment is worth it.

Who Should Use It

9Router is a good fit if you use multiple AI coding tools, multiple providers, subscription plus free or cheap tiers, and want a central fallback policy. It is less useful if you only use one model and one tool.

Its real value is turning scattered model access into a configurable local routing layer.

Summary

9Router is a local gateway for AI coding tools. It lets Claude Code, Codex, Cursor, Cline, and similar tools talk to http://localhost:20128/v1, while it handles model selection, format translation, token compression, quota tracking, and fallback.

It is best for heavy AI coding users who already switch between providers. Start with one tool and one provider, then add accounts and combos gradually.

References

记录并分享
Built with Hugo
Theme Stack designed by Jimmy