npx @subrouter/cli login anthropic npx @subrouter/cli login openai npx @subrouter/cli login xai npx @subrouter/cli login opencode-go npx @subrouter/cli login github-copilot npx @subrouter/cli login poe npx @subrouter/cli login minimax npx @subrouter/cli login kimi npx @subrouter/cli login zai npx @subrouter/cli login alibaba
npx @subrouter/cli import opencode
auth.json and writes matching accounts into ~/.subrouter/auth.json. Only providers Subrouter supports are imported. Existing accounts with the same identity are updated. The auth file schema is at auth.schema.json.npx @subrouter/cli status
default preset ranks the newest model from each provider. When Subrouter resolves a request, it skips providers without an account. You do not need to create a preset.@subrouter/opencode to the plugin array in ~/.config/opencode/opencode.json:{ "plugin": ["@subrouter/opencode"] }
subrouter/default.pi install npm:@subrouter/pi pi --model subrouter/default
provider/model candidates. Subrouter skips candidates in cooldown and retries quota or authentication failures on the next account or provider only before output starts. After output starts, tool follow-ups stay on that provider, model, and account until the agent settles. The next user message starts from the preset ranking again.opencode Go / Pi model: subrouter/default │ v ┌──────────────────────────┐ │ subrouter harness plugin │ │ @subrouter/opencode │ │ @subrouter/pi │ └──────────┬───────────────┘ │ v for each candidate in order (default preset: 1. anthropic 2. openai 3. xai 4. opencode-go 5. github-copilot 6. poe 7. minimax 8. kimi 9. zai 10. alibaba) v inspect each candidate │ ┬─────────────────────┼─────────────────────┬ v v v cooldown quota/auth failure output starts before output v v v skip cool down account stream │ v try next candidate │ v none left? ──> error
~/.subrouter/auth.json. Log in multiple times to the same provider to build a rotation pool.~/.subrouter/config.json). Once an account is rate limited, every session and every harness skips it until the cooldown expires.| Response | Cooldown |
429 rate limited | retry-after / retry-after-ms when present, otherwise 5 minutes |
| overloaded / at capacity | retry-after / retry-after-ms when present, otherwise 1 minute |
402 / quota exhausted | 10 minutes |
provider/model entries. Append #variant to pin reasoning effort, for example openai/gpt-5.5#high. Every preset shows up in opencode Go and Pi as subrouter/<preset-name>.OpenRouter / CLIProxyAPI OpenAI request ──> request translator ──> Anthropic / Gemini request OpenAI stream <── response translator <── Anthropic / Gemini stream Subrouter subrouter chooses account + model v ┌────────────────────┴────────────────────┐ v v OpenCode request ──> official AI SDK provider Pi request ──> Pi native provider │ │ v v provider-native API provider-native API
pi-ai package. Subrouter does not replace either implementation.| Subrouter | OpenRouter / CLIProxyAPI | |
| Main job | Rotate personal subscriptions | Provide a general API gateway |
| Protocol handling | Reuse the harness provider | Translate requests and responses |
| Streaming | Forward the harness-native stream | Parse and rebuild client-compatible streams |
| API server | None | OpenAI, Anthropic, Gemini, or other compatible endpoints |
| Scope | OpenCode and Pi on one machine | Many clients, providers, and deployment modes |
| Provider | Subscription | Login flow |
anthropic | Claude Pro / Max | OAuth (browser, PKCE) |
openai | ChatGPT Plus / Pro (Codex backend) | Browser OAuth (PKCE) or device code |
xai | SuperGrok / Grok Build | Device code |
opencode-go | opencode Go | API key from opencode.ai/auth |
github-copilot | GitHub Copilot | GitHub device code |
poe | Poe subscription points | Browser OAuth (PKCE) |
minimax | MiniMax Token Plan | Subscription key |
kimi | Kimi Code | Subscription key |
zai | Z.ai GLM Coding Plan | Subscription key |
alibaba | Alibaba Coding Plan | Subscription key |
npx @subrouter/cli, or install the shorter subrouter command globally:npm i -g @subrouter/cli
npx @subrouter/cli login [provider] [--input value] # add a subscription to the pool npx @subrouter/cli import opencode [--from path] # copy matching OpenCode logins npx @subrouter/cli logout [provider] [--force] # remove all accounts for a provider npx @subrouter/cli account list [--json] # accounts + cooldown status npx @subrouter/cli account status [provider] # exits 1 until login completes npx @subrouter/cli account remove [provider] [n|email] [--force] npx @subrouter/cli account order --provider anthropic work@x.com personal@x.com
account list numbers accounts from 1. Run login again with the same provider to add another account to its rotation pool. In a terminal, login with no provider shows a list to pick from.import opencode is for machines that already have OpenCode logins. It copies matching tokens from OpenCode auth.json into Subrouter. Use --from only when that file is not in the default OpenCode data directory.account order sets the fallback order inside one provider. Pass every account email. The first email is tried first.~/.subrouter/auth.json. Presets, cooldowns, and live routes live in ~/.subrouter/config.json. Each file includes a $schema URL so editors can autocomplete fields: auth.schema.json and config.schema.json.npx @subrouter/cli preset create <name> --models 'anthropic/claude-opus-4-6#max,xai/grok-4.6' [--force] npx @subrouter/cli preset list npx @subrouter/cli preset show [name] # includes currently usable candidates npx @subrouter/cli preset remove [name] [--force]
--models is the fallback order. Append #variant to pin reasoning effort for that candidate. preset create checks the variant against models.dev. A session --variant or subrouter/<name>#high still wins over the preset pin. Every preset appears in both harnesses as subrouter/<name>.npx @subrouter/cli status # everything at a glance npx @subrouter/cli cooldown clear [--force] # retry every account now
cooldown clear removes every provider and account cooldown and lets the next request retry them immediately. Use --force in a non-interactive shell.npx @subrouter/cli account status anthropic
account status exits 1 while a login is still running, even when older accounts are already stored, so polling it never mistakes yesterday's expired token for today's login.--input in non-interactive shells. Destructive commands ask for confirmation in a terminal and require --force elsewhere.53692, OpenAI uses 1455, and Poe prints a random port chosen for that login. When the browser cannot reach the server, copy the final redirect URL and replay it on the machine that started the login:curl 'http://localhost:53692/callback?code=...&state=...' # Authentication successful. You can close this window.
GET redirect request, so curl can replay the same redirect URL.subrouter login anthropic v ├──> callback server listens on 127.0.0.1:53692 <── curl replay works here │ └──> 30 min timeout ──> server closes ──> replay gets connection refused
login again. In an interactive terminal with the browser on another machine, set SUBROUTER_MANUAL_OAUTH=1; Subrouter prints the authorize URL, then asks for the final redirect URL.default preset is built in. It ranks the newest model from each provider in the order shown above. When Subrouter resolves a request, it skips providers without stored accounts. Create a preset named default to override it.@subrouter/opencode registers a subrouter provider inside opencode Go via the plugin config hook. Each preset becomes a model. For installation, see Connect your harness.subrouter/default (or any subrouter/<preset>) as the model. Presets created after opencode Go starts appear on the next opencode Go restart.npx @subrouter/cli login anthropic npx @subrouter/cli login anthropic # second Claude account npx @subrouter/cli login openai
subrouter/default as the session model. On a 429 or 402 before output starts, Subrouter retries the request with the next account in the preset.anthropic/... for openai/....{ "model": "subrouter/default", "agent": { "explore": { "model": "subrouter/default" }, "plan": { "model": "subrouter/default" } } }
subrouter/default.{ "agent": { "explore": { "model": "subrouter/default" } } }
~/.config/opencode/agents/:--- description: Fast read-only codebase search mode: subagent model: subrouter/default ---
model to subrouter/<preset> instead of a single provider model.parent session │ v Task tool │ v explore agent (model: subrouter/default) v ├──> first subscription 429 ──> cooldown │ └──> next subscription ──> task continues
@subrouter/pi registers the same presets as models in Pi. It delegates each request to Pi's native provider stream. Poe and Alibaba use Pi's native OpenAI-compatible provider API. Subrouter selects the subscription, but it does not translate requests or responses between provider formats.subrouter/default or another subrouter/<preset> model. Presets created after Pi starts appear after /reload or the next restart.subrouter command, so this one needs a global install rather than npx:npm i -g @subrouter/cli subrouter completions install
autoload -Uz compinit && compinit for zsh). Then Tab works:subrouter <TAB> # shows all commands subrouter pre<TAB> # completes to "preset" subrouter login --<TAB> # shows available options
subrouter completions uninstall
cli/ — @subrouter/cli: account stores, presets, cooldown state, provider adapters, and the routing engine (RouterModel, an AI SDK LanguageModelV3)opencode/ — @subrouter/opencode: the opencode Go plugin plus the provider entry opencode Go loadspi/ — @subrouter/pi: a native Pi provider that delegates to Pi's provider streams without format translationwebsite/ — private subrouter-website: the Holocron documentation site for subrouter.orgpnpm install pnpm build pnpm test
SUBROUTER_*_BASE_URL, and assert that a rate-limited provider cycles to the fallback through each complete pipeline. Pi uses in-memory auth, model, settings, and session stores, so tests never read or write the real Pi config.| Variable | Purpose |
SUBROUTER_HOME | State directory (default ~/.subrouter) |
SUBROUTER_MANUAL_OAUTH | Ask for pasted redirect URL (browser on another machine) |
SUBROUTER_MODELS_DEV_URL | Override the models.dev catalog URL (tests) |
SUBROUTER_ANTHROPIC_BASE_URL | Override the Anthropic API base URL (tests) |
SUBROUTER_OPENAI_BASE_URL | Override the Codex API base URL (tests) |
SUBROUTER_OPENAI_ISSUER_URL | Override the OpenAI auth host (tests) |
SUBROUTER_XAI_BASE_URL | Override the xAI API base URL (tests) |
SUBROUTER_OPENCODE_GO_BASE_URL | Override the OpenCode Go base URL (tests) |
SUBROUTER_GITHUB_COPILOT_BASE_URL | Override the GitHub Copilot API base URL (tests) |
SUBROUTER_GITHUB_COPILOT_GITHUB_URL | Override the GitHub OAuth host (tests) |
SUBROUTER_GITHUB_COPILOT_GITHUB_API_URL | Override the GitHub API host (tests) |
SUBROUTER_POE_BASE_URL | Override the Poe API base URL (tests) |
SUBROUTER_POE_AUTHORIZE_URL | Override the Poe authorization URL (tests) |
SUBROUTER_POE_TOKEN_URL | Override the Poe token URL (tests) |
SUBROUTER_MINIMAX_BASE_URL | Override the MiniMax API base URL (tests) |
SUBROUTER_KIMI_BASE_URL | Override the Kimi Code API base URL (tests) |
SUBROUTER_ZAI_BASE_URL | Override the Z.ai API base URL (tests) |
SUBROUTER_ALIBABA_BASE_URL | Override the Alibaba Coding Plan API base URL (tests) |
SUBROUTER_MANUAL_OAUTH=1 when the browser that authorizes is not on the
machine running subrouter. The localhost callback can never fire there, so
browser login switches to asking for the redirect URL instead. Harnesses that
drive login remotely (kimaki's Discord /login) set this for you.