anyr opencode

Route OpenCode through AnyRouter with one CLI command, or a custom provider in opencode.json.

Route OpenCode through AnyRouter for one key, unified billing and request logs across every model.

Setup

curl -fsSL https://anyrouter.dev/cli.sh | bash
anyr opencode

AnyRouter CLI launcher with the OpenCode target selected

The first run signs you in (browser, or device code on SSH/headless; --key, --paste and --device force a path, see Login). The key is saved to ~/.anyrouter/config.yaml and shared with the other launchers.

anyr opencode --model "anthropic/claude-sonnet-4-6"   # pin a model
anyr opencode --model auto -- --help                  # flags after -- go to OpenCode
anyr opencode --dry-run                               # print resolved environment, run nothing

The launcher does not write OpenCode's config files. It injects an OPENCODE_CONFIG_CONTENT provider for that process only, so your global opencode.json is unchanged. See the configuration reference for all flags.

MCP tools

anyr opencode connects the AnyRouter MCP gateway with the session's key when Auto-connect in coding agents is on in the dashboard. Turn it off with --no-mcp, anyr mcp auto off, or in the dashboard.

Verify

Run a prompt in OpenCode; the call appears in your request logs within a second or two with model, tokens and cost. anyr opencode --dry-run prints the resolved command and inline provider config (the key is never embedded, only {env:OPENAI_API_KEY}).

Troubleshooting

SymptomFix
401 or auth errorsPersistent config: echo $ANYROUTER_API_KEY must print a live sk-ar- key. CLI: anyr config get, or re-run anyr setup.
Config invalid / missing limit.outputOpenCode 1.18+ needs both limit.context and limit.output. Add "output": 65536 or drop limit. The CLI writes both.
Model not foundThe models key must be an exact id (anthropic/claude-sonnet-4-6, not claude-sonnet-4-6); the default model is anyrouter/<id>.
Requests still hit OpenCode Zen or another providerA global opencode.json pointing at Zen, or a /connect credential, can win when you launch opencode yourself. Check ~/.config/opencode/opencode.json; AnyRouter models are namespaced anyrouter/….

AnyRouter routes requests to third-party models. Models and outputs are provided as is, with no warranty; you use them at your own risk. Disclaimer