Run OpenCode through AnyRouter
One CLI command injects an AnyRouter provider for the session, or add a custom provider in opencode.json — one key, the Chat Completions catalog, and request logs.
The problem
What this is for
OpenCode's built-in providers each want their own key. Switching models or sharing billing with Claude Code and Codex means editing every tool separately.
What to do
Three steps, then copy
- 1.Create an AnyRouter key in the dashboard (sk-ar-…), or let the CLI sign you in.
- 2.Launch with anyr opencode so it injects the provider for that session, or add AnyRouter to opencode.json for a persistent config.
- 3.Pick an anyrouter/… model in /models and confirm the call in request logs.
anyr opencode{
"$schema": "https://opencode.ai/config.json",
"provider": {
"anyrouter": {
"npm": "@ai-sdk/openai-compatible",
"name": "AnyRouter",
"options": {
"baseURL": "https://anyrouter.dev/api/v1",
"apiKey": "{env:ANYROUTER_API_KEY}"
},
"models": {
"anthropic/claude-sonnet-4.6": {
"name": "Claude Sonnet 4.6"
}
}
}
},
"model": "anyrouter/anthropic/claude-sonnet-4.6"
}Ready to try it
The guide has the full walkthrough. Sign up if you still need a key.
Related
Next playbooks
Run Claude Code through AnyRouter
Install the anyr CLI, then anyr claude — it injects the base URL, key, and model. Env vars are the fallback if you already run claude yourself.
OpenRun every coding agent through one URL
Claude Code, Codex, OpenCode, Cursor, and other OpenAI-compatible tools share 217+ models, one balance, and one request log.
OpenGive agents MCP tools without per-client sprawl
Understand what an MCP server is, then connect agents to AnyRouter instead of pasting a new config into every app.
Open