@sifxprime/krouter

中文文档
0.5.168发布于 2026/11/02MIT构建来源已验证

Local AI gateway for Claude Code, Cursor, Codex, Copilot, Cline and any OpenAI-compatible client. Route 40+ LLM providers and 100+ models through one endpoint with automatic fallback, OAuth key management and 20-40% token savings.

原始使用文档
文档目录34 节
  1. Quick Start
  2. CLI Options
  3. From Source (Contributors)
  4. Docker
  5. Why kRouter?
  6. How It Works
  7. PII Redaction with Presidio
  8. Features
  9. Supported CLI Tools
  10. Supported Providers
  11. OAuth (Bring Your Subscription)
  12. Free Tier (with API key)
  13. Free (account sign-in or no auth)
  14. API Key Providers (65+)
  15. Browser Session
  16. Setup Guide
  17. Step 1 · Install
  18. Step 2 · Start in Background
  19. Step 3 · Add a Provider
  20. Step 4 · Point Your AI Tool at kRouter
  21. Environment Variables
  22. Deployment
  23. VPS
  24. Docker
  25. PM2
  26. API
  27. Chat Completions
  28. List Models
  29. Uninstall
  30. Troubleshooting
  31. Tech Stack
  32. Links
  33. Credits
  34. License
kRouter — Kodelyth AI Infrastructure

kRouter — Kodelyth AI Infrastructure

The universal AI router that saves 20–40% input tokens and falls back when a provider fails.

Connect Claude Code, Cursor, Antigravity, Kiro, Copilot, Codex, OpenCode, Cline, OpenClaw, and any OpenAI-compatible client to 95+ AI providers and 100+ models through one self-hosted endpoint. Route intelligently. Fall back instantly. Save tokens automatically.

npm GitHub Website License

Website & Full Docs — krouter.kodelyth.com

Quick Start • Features • Setup • Supported Providers

You're viewing this on npm. Full docs, screenshots, and changelog: github.com/sifxprime/krouter.


Quick Start

Requires Node.js 20.9 or newer.

# Install globally from npm
npm install -g @sifxprime/krouter

# Run in background (tray mode)
krouter -t

The dashboard is at http://localhost:20128/dashboard — open it in your browser, or from the tray icon.

First login: the default dashboard password is 123456. Change it under Settings → Security once you're in. For safety, the default only works from the machine kRouter is running on — sign-ins from other devices on your network are refused until you set your own. Under Docker that includes your own browser, so set INITIAL_PASSWORD as shown below.

Prefer the foreground? Run krouter with no flag, and add -l to see the server logs.

CLI Options

krouter --help

Options:
  -p, --port <port>   Port to run the server (default: 20128)
  -H, --host <host>   Host to bind (default: 0.0.0.0)
  -l, --log           Show server logs (default: hidden)
  -t, --tray          Run in system tray mode (background)
  --skip-update       Skip auto-update check
  -h, --help          Show this help message
  -v, --version       Show version

The default host 0.0.0.0 makes kRouter reachable from your network; remote callers still need an API key for /v1/* and a login for the dashboard. Use --host 127.0.0.1 to keep it local-only. The krouter command ignores the PORT and HOSTNAME environment variables, so set the port and host with these flags.

From Source (Contributors)

git clone https://github.com/sifxprime/krouter.git
cd krouter
npm install
npm run dev

Docker

KROUTER_PASSWORD="$(openssl rand -base64 18)" && echo "Dashboard password: $KROUTER_PASSWORD"
docker run -d \
  -p 20128:20128 \
  -e INITIAL_PASSWORD="${KROUTER_PASSWORD:?run the line above first}" \
  -v "$HOME/.krouter:/app/data" \
  --name krouter \
  sifxprime/krouter:latest

The first line makes a random password and prints it. Log in with it, then set your own under Settings → Security; until you do, the password is whatever INITIAL_PASSWORD the container started with. Under Docker the default 123456 is refused, because your browser's requests reach the container from outside it. If ~/.krouter already holds a password from an npm install, that one is used. Forgot it? With image 0.5.162 or newer: docker exec krouter node scripts/reset-password.js (see DOCKER.md).

With PII Redaction (Presidio)

To enable automatic PII redaction before sending requests to AI providers. Compose builds kRouter and the sidecar from source, so it runs from a clone. KROUTER_INITIAL_PASSWORD has no default — compose refuses to start without it. The second line saves a random one to .env, where compose reads it on every start, and prints it: that is your dashboard password.

git clone https://github.com/sifxprime/krouter.git && cd krouter
echo "KROUTER_INITIAL_PASSWORD='$(openssl rand -base64 18)'" > .env && cat .env
docker compose up -d

Not using Docker? kRouter has no Python dependency — run the sidecar separately. kRouter looks for it at http://127.0.0.1:5001/redact; set SIDECAR_URL if it runs anywhere else. See the setup guide below.

Redaction is off by default; enable it from the Presidio page in the dashboard sidebar.

See docs/REDACTION_SETUP.md for full configuration and customization options.

Then open http://localhost:20128/dashboard.


Why kRouter?

Stop wasting money, tokens, and hitting limits:

  • Subscription quota expires unused every month
  • Rate limits stop you mid-coding
  • Tool outputs (git diff, grep, ls…) burn tokens fast
  • Paying separately for every provider's API adds up
  • Manually switching between providers

kRouter solves this:

  • RTK Token Saver — on by default; compresses tool outputs to save 20–40% of input tokens per request
  • Zenith routing — scores each account by success rate, latency and remaining quota, and skips accounts that are cooling down
  • Multi-account rotation — round-robin across accounts, with quota tracking for providers that report it
  • Auto token refresh — OAuth tokens refresh transparently
  • Universal client support — works with OpenAI, Anthropic, Responses, Gemini and Ollama-format clients
  • MITM interception — routes Antigravity, GitHub Copilot, Kiro IDE and Claude Desktop through kRouter (not inside Docker)

How It Works

┌─────────────┐
│  Your CLI   │  (Claude Code, Codex, OpenClaw, OpenCode, Cline…)
│   Tool      │
└──────┬──────┘
       │ http://localhost:20128/v1
       ↓
┌─────────────────────────────────────────────┐
│           kRouter (Smart Router)            │
│  • RTK Token Saver (cut tool_result tokens) │
│  • Zenith account scoring                   │
│  • Format translation (OpenAI ↔ Claude)     │
│  • Live quota tracking                      │
│  • Auto token refresh                       │
└──────┬──────────────────────────────────────┘
       │
       ├─→ [SUBSCRIPTION] Claude Code · Codex · Copilot · Cursor
       │
       ├─→ [FREE TIER] Cloudflare · Vertex · Gemini · Ollama Cloud · OpenRouter
       │
       └─→ [FREE] Kiro · Gemini CLI · Qoder · OpenCode Free · MiMo Code Free

If an account fails or hits a rate limit, kRouter moves to the next account for that provider. Put models from several providers in a combo and it falls back across them in turn — with zero manual intervention.


PII Redaction with Presidio

Optional, and off by default. When enabled, kRouter strips personal data — names, emails, phone numbers, API keys — from prompts before they leave your machine, using Microsoft Presidio as a local sidecar (needs Docker or Python). It fails closed: if the sidecar is down, times out or errors, the request is rejected (503 / 502) rather than sent unredacted. It covers the chat, Messages, Responses, Ollama and Gemini-format routes; embeddings, audio, images, search and fetch are not redacted.

Setup, configuration, custom patterns, testing and troubleshooting: docs/REDACTION_SETUP.md.

Features

FeatureWhat It DoesWhy It Matters
RTK Token SaverCompresses tool outputs (git diff, grep, ls, tree…) in requests. On by defaultSave 20–40% input tokens on requests that carry tool output
Zenith RoutingScores accounts by success rate, latency, remaining quota and priorityPicks the healthiest account; rate-limited accounts cool down instead of being retried
Smart FallbackCombos you build, e.g. Subscription → Free tier → FreeNever stop coding
Real-Time QuotaRemaining %, reset countdown, exhaustion badge for providers that report quotaMaximize every subscription
Format TranslationOpenAI ↔ Claude ↔ Gemini ↔ Cursor ↔ Kiro ↔ VertexWorks with any CLI tool
Multi-AccountMultiple accounts per provider with rotation strategiesLoad balancing + redundancy
Auto Token RefreshOAuth tokens refresh automaticallyNo manual re-login
Custom CombosNamed model combinations with fallback, round-robin or fusion strategyTailor fallback to your workflow
System TrayRuns quietly in background with tray iconSet-and-forget deployment
Deploy AnywhereLocalhost · VPS · Docker · PM2, with remote access through Cloudflare Tunnel or TailscaleWherever you need it
PII RedactionOptional, off by default: redacts names, emails, phones and API keys using Microsoft PresidioProtect privacy before sending to AI providers

Full feature guide → krouter.kodelyth.com


Supported CLI Tools

Claude Code
Claude Code
OpenClaw
OpenClaw
Codex
Codex
OpenCode
OpenCode
Cursor
Cursor
Antigravity
Antigravity
Cline
Cline
Continue
Continue
Droid
Droid
Roo
Roo
Copilot
Copilot
Kilo Code
Kilo Code

Supported Providers

95+ providers in five groups, plus any OpenAI- or Anthropic-compatible endpoint you add yourself.

OAuth (Bring Your Subscription)

Claude Code · Antigravity · Codex · GitHub Copilot · Cursor · xAI · Kilo Code · Cline · ClinePass · Grok CLI · Kimchi

Free Tier (with API key)

Cloudflare Workers AI · Vertex AI · Gemini · Ollama Cloud · OpenRouter · BytePlus ModelArk · Atomesus · NVIDIA NIM · Poolside

Free (account sign-in or no auth)

Kiro AI · Gemini CLI · CodeBuddy CN · Qoder · OpenCode Free · MiMo Code Free

Kiro, Gemini CLI, Qoder, Claude Code, Antigravity, Codex and GitHub Copilot use subscription sessions that are not licensed for proxy use. The dashboard warns before you connect them: the account may be restricted or banned.

API Key Providers (65+)

OpenAI · Anthropic · GLM · Kimi · MiniMax · DeepSeek · Groq · xAI · Mistral · Perplexity · Together AI · Fireworks · Cerebras · Cohere · SiliconFlow · Hyperbolic · Nebius · Chutes · and 45+ more

Browser Session

Grok Web · Perplexity Web (Pro/Max)

Full provider setup guide → krouter.kodelyth.com


Setup Guide

Step 1 · Install

npm install -g @sifxprime/krouter

Step 2 · Start in Background

krouter -t

You'll see a tray icon in your menu bar. Right-click for Open Dashboard or Quit.

Step 3 · Add a Provider

  1. Open http://localhost:20128/dashboard
  2. Go to Providers, pick one (Cloudflare Workers AI is a good free start) and click Add
  3. Paste your API key or complete the OAuth login
  4. Click Test on a model to check it answers

Step 4 · Point Your AI Tool at kRouter

Endpoint:  http://localhost:20128/v1
API Key:   a key from Dashboard → Endpoint → API Keys   (local callers can skip it)
Model:     kr/claude-sonnet-4.5   (or any provider/model)

Works with any OpenAI-compatible client. A Default Key is created the first time you open the Endpoint page. Local requests need no key unless REQUIRE_API_KEY=true; requests from other machines always do. Cursor is the exception to localhost: it sends requests through its own servers, so turn on the Tunnel on the Endpoint page and use that URL with a key.

Detailed integration guide (Claude Code, Cursor, Cline, and more) → krouter.kodelyth.com


Environment Variables

VariableDefaultDescription
PORT20128Server port for the Docker image and node custom-server.js. The krouter command ignores it — use --port
HOSTNAME0.0.0.0Bind host for the Docker image and node custom-server.js. The krouter command ignores it — use --host 127.0.0.1 for local-only
DATA_DIR~/.krouterData directory (SQLite, certs, cache). %APPDATA%\krouter on Windows
INITIAL_PASSWORD—First-login dashboard password. Unset, it is 123456, accepted only from the same machine
NODE_ENVproductionRuntime mode
REQUIRE_API_KEYfalseRequire a Bearer key on /v1/* from every caller. Remote callers always need one; this additionally removes the loopback exemption, for shared or multi-user machines
KROUTER_SKIP_RUNTIME_HEALfalseSkip the startup npm self-heal of the SQLite/tray runtime (air-gapped or CI machines)
AUTH_COOKIE_SECUREfalseForce Secure cookie (set behind HTTPS reverse proxy)
HTTP_PROXY / HTTPS_PROXY / ALL_PROXY / NO_PROXY—Outbound proxy config

Full env reference → krouter.kodelyth.com


Deployment

VPS

npm install -g @sifxprime/krouter
krouter --skip-update --host 127.0.0.1 --port 20128

Put Nginx or Caddy in front for HTTPS; --host 127.0.0.1 keeps the port closed to everything but the proxy. Or skip the proxy and use the built-in Cloudflare Tunnel or Tailscale from the Endpoint page.

Docker

KROUTER_PASSWORD="$(openssl rand -base64 18)" && echo "Dashboard password: $KROUTER_PASSWORD"
docker run -d -p 20128:20128 -e INITIAL_PASSWORD="${KROUTER_PASSWORD:?run the line above first}" -v "$HOME/.krouter:/app/data" --name krouter sifxprime/krouter:latest

PM2

npm install -g @sifxprime/krouter pm2
pm2 start krouter --name krouter -- --skip-update
pm2 save
pm2 startup

API

Chat Completions

POST http://localhost:20128/v1/chat/completions
Authorization: Bearer <your-api-key>
Content-Type: application/json

{
  "model": "kr/claude-sonnet-4.5",
  "messages": [{"role": "user", "content": "Hello"}],
  "stream": true
}

List Models

GET http://localhost:20128/v1/models
Authorization: Bearer <your-api-key>

Returns every configured provider + custom combo in OpenAI format.


Uninstall

# Stop kRouter (right-click tray → Quit, or pkill -f krouter)
npm uninstall -g @sifxprime/krouter
rm -rf ~/.krouter   # optional: wipe database + certs

Troubleshooting

"No active credentials for provider" — Add or reconnect the provider in Dashboard → Providers.

Rate limited — kRouter cools the account down and moves to the next one. To speed it up, add more accounts or configure a combo.

MITM cert errors — Install or reinstall the root CA from the MITM page in the dashboard sidebar (Install Certificate / Reinstall Certificate).

Dashboard on wrong port — the krouter command ignores PORT; pass the port as a flag: krouter -t --port 20128. If another program holds the port, kRouter will not stop it and suggests another one.

Full troubleshooting guide → krouter.kodelyth.com


Tech Stack

  • Runtime: Node.js 20.9+
  • Framework: Next.js 16
  • UI: React 19 + Tailwind CSS 4
  • Database: SQLite (better-sqlite3 / node:sqlite / sql.js)
  • Streaming: Server-Sent Events (SSE)
  • Auth: OAuth 2.0 (PKCE) + JWT + API Keys


Credits

kRouter is a hardened fork of the upstream decolua/9router. Huge thanks to @decolua and the 9router contributors for the original project. Star them on GitHub.


License

MIT License — see LICENSE for details.


版本与发布记录

@sifxprime/krouter 共发布 137 个版本,首次发布于 2026/06/17;过去 12 个月发布了 137 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.5.168latest2026/11/021 天前
0.5.1672026/11/021 天前
0.5.1662026/10/1915 天前
0.5.1652026/10/1915 天前
0.5.1642026/10/0826 天前
0.5.1632026/10/0529 天前

关于 @sifxprime/krouter 的常见问题

@sifxprime/krouter 是什么?

本地AI网关Claude Code, Cursor, Codex, Copilot, Cline和任何openai兼容的客户端。路由40多个LLM提供商和100多个模型通过一个端点,具有自动回退,OAuth密钥管理和20-40%的令牌节省。

如何安装 @sifxprime/krouter?

在项目目录运行 npm install @sifxprime/krouter,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 krouter,可以用 npx krouter 直接运行。

@sifxprime/krouter 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/sifxprime__krouter 是否存在。

@sifxprime/krouter 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.9.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@sifxprime/krouter 可以商用吗?

@sifxprime/krouter 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@sifxprime/krouter 还在维护吗?

最新版本 0.5.168 发布于 2026/11/02(1 天前);至今共发布 137 个版本,其中过去 12 个月发布了 137 个;首次发布于 2026/06/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。