Setup guide - Documented by OpenRouter
Use OpenRouter in OpenCode
OpenCode has OpenRouter as a built-in provider. You connect it with /connect in the TUI or under Settings > Providers in the desktop app, and can add any OpenRouter slug under provider.openrouter.models in opencode.json. OpenRouter publishes an official guide for this setup.
Last verified 9 steps2 official sources
Steps
- Step 1.
Install OpenCode.
Terminalcurl -fsSL https://opencode.ai/install | bash - Step 2.
Or install with npm or Homebrew.
Terminalnpm install -g opencode-ai brew install anomalyco/tap/opencode - Step 3.
Start OpenCode in your project directory.
Terminalcd /path/to/your/project opencode - Step 4.
Run /connect, search for OpenRouter, and paste your OpenRouter API key when prompted.
Snippet/connect - Step 5.
Run /models to pick a model. Many OpenRouter models are preloaded.
Snippet/models - Step 6.
Optional: add more OpenRouter models in opencode.json, using the OpenRouter slug as the key.
JSON{ "$schema": "https://opencode.ai/config.json", "provider": { "openrouter": { "models": { "~anthropic/claude-sonnet-latest": {}, "~google/gemini-flash-latest": {} } } } } - Step 7.
Optional: set a default model. OpenCode model ids are provider_id/model_id, so prefix the slug with openrouter/.
JSON{ "$schema": "https://opencode.ai/config.json", "model": "openrouter/~anthropic/claude-sonnet-latest" } - Step 8.
Optional: write the key directly to ~/.local/share/opencode/auth.json.
JSON{ "openrouter": { "type": "api", "key": "sk-or-v1-your-key-here" } } - Step 9.
Check that the credential was stored.
Terminalopencode auth list
Caveats
- OpenCode handles the OpenRouter endpoint itself as a built-in provider. You set no base URL.
- The leading ~ in slugs such as ~anthropic/claude-sonnet-latest is intentional. These are OpenRouter latest aliases.
- If no OpenRouter models show up after connecting, fully quit and restart OpenCode. The provider catalog is read at startup.
- Desktop app: Settings > Providers > OpenRouter > Connect > API key. The desktop app and the terminal share one set of credentials.
More setup guides
Same tool, other providers
Related reading
- Model Routing Recipes: Practical Config Patterns to Cut AI SpendModel routing recipes with paste-ready OpenRouter and LiteLLM configs for task tiers, fallback chains, cost ceilings and cache-aware routing that cut AI spend.
- OpenRouter Fusion Makes Model Panels Real. Use Them Like Escalation, Not AutopilotOpenRouter Fusion turns multi-model panels into an API feature. Use it as an escalation lane for prompts where a wrong answer is expensive, not as the default.
- OpenRouter in 2026: Review, Setup, and When Model Routing PaysOpenRouter review and setup - one API key for 300+ models with fallbacks and provider routing, what it costs, and when to go direct to a provider instead.
- LLM Routers Compared: LiteLLM vs Portkey vs OpenRouter in 2026LiteLLM vs Portkey vs OpenRouter compared for production AI apps: cost tracking, fallbacks, caching, and load balancing, plus when to use each router.
- OpenCode Background Subagents: What v2.3.0 ChangesOpenCode v2.3.0 makes every subagent run in the background and defaults transcripts to low verbosity. What changed, what to set, and where it bites.
- OpenCode Cache Warming: What v2.2.7 Changed and When to Turn It OnOpenCode v2.2.7 makes cache warming time its pings from the model cache TTL. The config, the cost of idle pings, and when warming is a bad trade.
FAQ
How do I use OpenRouter in OpenCode?
OpenCode has OpenRouter as a built-in provider. You connect it with /connect in the TUI or under Settings > Providers in the desktop app, and can add any OpenRouter slug under provider.openrouter.models in opencode.json. OpenRouter publishes an official guide for this setup.
Which OpenRouter model ids work in OpenCode?
The official docs read for this guide list ~anthropic/claude-sonnet-latest, ~google/gemini-flash-latest, openrouter/~anthropic/claude-sonnet-latest and anthropic/claude-sonnet-4.5.
Is this an official OpenRouter and OpenCode setup?
OpenRouter documents this setup in its own docs. It was last checked against 2 official pages on November 8, 2026.
Sources
Last verified against 2 official pages.
Newsletter
New models, set up the day they ship
One email per week. New model releases, the coding tools that support them and how to wire them up.