OpenCode with AnyRouter — free models, one API key

Point OpenCode at AnyRouter's base URL. Use free models with anyrouter/free, or any Chat Completions model with one sk-ar- key.

Run OpenCode on any AnyRouter model with one sk-ar- key. It is a config-only change. Flags, profiles and login details are in the OpenCode CLI setup; to add AnyRouter's MCP tools see MCP with OpenCode.

Set it up

One command handles login, the key, and a session-only provider (opens a browser, or shows a device code over SSH):

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

Pin a model or forward flags: anyr opencode --model "z-ai/glm-5.2", anyr opencode --model auto -- --help.

Confirm the call appears in your request logs.

Free models and auto routing

Model idBehavior
anyrouter/freeBest free model available now, with fallback. No credits. Unlock with a $5 top-up, Go or higher, or one donated key; no daily cap. See Free Tier.
anyrouter/autoTop free and paid models with health-aware failover. Paid members use credits.
anyr opencode --model anyrouter/free

In a persistent config, add "anyrouter/free": { "name": "AnyRouter Free" } to models and select anyrouter/anyrouter/free. A 400 no_eligible_models means your privacy or routing settings (for example Zero Data Retention or blocked providers) excluded every candidate: relax them or pick a specific model.

To use your own provider keys, see BYOK.

MCP auto-connect

anyr opencode connects the AnyRouter MCP gateway with the session 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.

Troubleshooting

SymptomFix
401 or 403Check the key is active, and that ANYROUTER_API_KEY is set in OpenCode's environment or a CLI profile exists (anyr config get).
Model not foundThe models key must match an id in the catalog, and you select it as anyrouter/<id>.
Invalid config, missing limit.outputSet both limit.context and limit.output, or omit limit.
Another provider answersA /connect login (OpenCode Zen) or leftover openai provider can win. Pick the anyrouter/... model in /models, or launch with anyr opencode.

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