@afg473319/afrouter

中文文档
0.5.98发布于 2026/10/12MIT构建来源已验证近 30 天下载 1940

AFRouter CLI - Start and manage AFRouter server

原始使用文档
文档目录9 节
  1. 🤔 Why AFRouter?
  2. ⚡ Quick Start
  3. 🚀 CLI Options
  4. 🤖 Headless Mode (scripts & AI agents)
  5. 🛠️ Supported CLI Tools
  6. 💾 Data Location
  7. 📚 Documentation
  8. 🙏 Acknowledgments
  9. 📄 License

AFRouter — FREE AI Router & Token Saver

Never stop coding. Save 20-40% tokens with RTK + auto-fallback to FREE & cheap AI models.

Connect All AI Code Tools (Claude Code, Cursor, Antigravity, Copilot, Codex, Gemini, OpenCode, Cline, OpenClaw...) to 40+ AI Providers & 100+ Models.

AFRouter is a maintained personal fork of 9Router. It ships extra providers and fixes not yet upstream — Nous Portal (Hermes CLI OAuth), OrcaRouter, concurrent model testing on provider cards, and a multi-model Grok Build integration — with its own command (afrouter) and separate data directory.

npm Downloads License

⭐ Upstream 9Router • 🧭 AFRouter repo


🤔 Why AFRouter?

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
  • ❌ Expensive APIs ($20-50/month per provider)

AFRouter solves this (all of 9Router's core, plus the fork's extras):

  • ✅ RTK Token Saver - Auto-compress tool_result, save 20-40% tokens
  • ✅ Maximize subscriptions - Track quota, use every bit before reset
  • ✅ Auto fallback - Subscription → Cheap → Free, zero downtime
  • ✅ Multi-account - Round-robin between accounts per provider
  • ✅ Universal - Works with any OpenAI/Claude-compatible CLI
  • ✅ Fork extras - Nous Portal, OrcaRouter, multi-model Grok Build, concurrent model tests

⚡ Quick Start

npm install -g @afg473319/afrouter
afrouter

# Or run directly with npx
npx @afg473319/afrouter

🎉 Dashboard opens at http://localhost:20128

Runs alongside 9Router? Yes — AFRouter keeps its data in its own directory, so it does not share state with a stock 9Router install. Only run one of them on port 20128 at a time, or start the second with --port.

2. Connect a FREE provider (no signup needed):

Dashboard → Providers → Connect Kiro AI (free Claude unlimited) or OpenCode Free (no auth) → Done!

3. Use in your CLI tool:

Claude Code/Codex/OpenClaw/Cursor/Cline Settings:
  Endpoint: http://localhost:20128/v1
  API Key:  [copy from dashboard]
  Model:    kr/claude-sonnet-4.5

That's it! Start coding with FREE AI models.

Docker? AFRouter is npm-only for now — use upstream 9Router's Docker images if you deploy in a container.


🚀 CLI Options

afrouter                    # Start with default settings (port 20128)
afrouter --port 8080        # Custom port
afrouter --no-browser       # Don't open browser
afrouter --skip-update      # Skip auto-update check
afrouter --help             # Show all options

Dashboard: http://localhost:20128/dashboard


🤖 Headless Mode (scripts & AI agents)

Headless mode exposes many dashboard operations non-interactively, but parity is not yet complete. See ../CLI_AUDIT.md for known gaps and the current repair scope. Headless commands talk to the already-running gateway and bypass the launcher:

afrouter <domain> <action> [flags]
afrouter status
afrouter providers list
afrouter models list --filter claude
afrouter chat --model cc/claude-sonnet-5 --prompt "say hi"
echo "summarize: ..." | afrouter chat --model ag/gemini-3-flash

Conventions:

  • JSON on stdout by default (agent-friendly); --human prints tables instead.
  • Errors go to stderr with exit codes: 0 ok, 1 error, 2 usage error.
  • Target gateway: --port/-p (default 20128, or AFROUTER_PORT), --host/-H (default 127.0.0.1, or AFROUTER_HOST).
  • Auth: automatic via the local machine token — no login needed on the same machine.
  • Full reference: afrouter <domain> --help (per-domain help is the source of truth).
DomainExamples
statusafrouter status — health + version
providerslist, test <id>, test-batch --mode all, enable/disable <id>, add --provider openai --name Main --api-key sk-...
nodeslist, add --name X --prefix x --base-url https://... --type openai-compatible
keyslist, create --name ci, delete <id>
comboslist, create --name route --models cc/claude-sonnet-5,cx/gpt-5.2, presets --source claude
modelslist --filter <q>, ping --model <m>, alias-set --alias a --model <m>, pricing
usagestats --period 7d, requests --provider cline --page-size 50, connection <id>
settingsget, set --key rtkEnabled --value false, db-export --file backup.json, shutdown
networkendpoint, tunnel-on/tunnel-off, pools, pxpipe-stats, tailscale-enable
toolsstatuses, setup --tool kilo --model cc/claude-sonnet-5, reset --tool cline
mediavoices --provider edge-tts --lang en
chatchat --model <m> --prompt <text> (or piped stdin; --system, --max-tokens, --temperature)
## 🔌 Connect to a Remote AFRouter

Already running 9Router on another machine (e.g. a team server on your LAN)? Point this machine's CLI tools at it — no local server is started:

npx @afg473319/afrouter connect http://<server-host>:20128                       # pick tools interactively
npx @afg473319/afrouter connect http://<server-host>:20128 --tools claude,codex  # or choose up front
npx @afg473319/afrouter connect --reset --tools claude,codex                     # undo

It logs in with the dashboard password (hidden prompt), reuses or creates an API key named cli-<hostname>, and writes each tool's config (backing up the original once as *.bak-afrouter).

Supported: claude, codex, opencode, droid, crush, kilo, cline, or all. Other options: --model, --opus/--sonnet/--haiku/--fable, --api-key, --key-name, --print-env. See afrouter connect --help.

⚠️ Over plain http:// the password and API key are sent unencrypted — use a trusted LAN/VPN or put HTTPS in front. The API key is stored in each tool's config file.


🛠️ Supported CLI Tools

Claude-Code • OpenClaw • Codex • OpenCode • Cursor • Antigravity • Cline • Continue • Droid • Roo • Copilot • Kilo Code • Gemini CLI • Qwen Code • iFlow • Crush • Crusher • Aider

Any tool supporting OpenAI/Claude-compatible API works.


💾 Data Location

AFRouter keeps its state separate from 9Router:

  • macOS/Linux: ~/.afrouter/db/data.sqlite
  • Windows: %APPDATA%/afrouter/db/data.sqlite
  • Override with the DATA_DIR environment variable.

📚 Documentation


🙏 Acknowledgments

📄 License

MIT License — see LICENSE for details.

版本与发布记录

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

版本发布日期距今
0.5.98latest2026/10/1226 天前
0.5.972026/10/1227 天前
0.5.962026/10/1028 天前
0.5.952026/10/1029 天前
0.5.942026/10/0929 天前
0.5.932026/10/0930 天前

关于 @afg473319/afrouter 的常见问题

@afg473319/afrouter 是什么?

AFRouter CLI - Start and manage AFRouter server

如何安装 @afg473319/afrouter?

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

@afg473319/afrouter 支持 TypeScript 吗?

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

@afg473319/afrouter 需要什么版本的 Node.js?

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

@afg473319/afrouter 可以商用吗?

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

@afg473319/afrouter 的下载量有多少?

根据 npm 官方下载统计,@afg473319/afrouter 在 2026/10/05 – 2026/11/03 这 30 天内被下载 1,940 次,日均约 65 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@afg473319/afrouter 还在维护吗?

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