OpenCode
OpenCode is an open-source terminal AI coding agent with TUI / CLI modes. It bundles @ai-sdk/anthropic and @ai-sdk/openai-compatible adapters, so WRouter's Anthropic and OpenAI endpoints both work out of the box.
- Website: https://opencode.ai
- GitHub: https://github.com/opencode-ai/opencode
Prerequisites
| Item | Requirement |
|---|---|
| OpenCode | Installed |
| WRouter | A working sk- token |
Option A: interactive setup (recommended for new users)
- Launch OpenCode TUI
- Type
/connect - Pick Other (custom endpoint)
- Fill in:
- Base URL:
https://wrouter.ai/v1 - API Key:
sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
- Base URL:
- Save; switch model with
/models
Option B: config file (recommended for long-term / multi-project)
Config locations (project-level overrides global):
- Global:
~/.config/opencode/opencode.json - Project:
opencode.jsonat the project root
json
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"wrouter-anthropic": {
"npm": "@ai-sdk/anthropic",
"name": "wrouter (Anthropic)",
"options": {
"baseURL": "https://wrouter.ai/v1",
"apiKey": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
"models": {
"claude-sonnet-4-6": {
"name": "Claude Sonnet 4.6",
"limit": { "context": 200000, "output": 8192 }
},
"haiku": {
"id": "claude-haiku-4-5",
"name": "Claude Haiku 4.5 (fast)",
"limit": { "context": 200000, "output": 8192 }
}
}
},
"wrouter": {
"npm": "@ai-sdk/openai-compatible",
"name": "wrouter",
"options": {
"baseURL": "https://wrouter.ai/v1",
"apiKey": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
"models": {
"gpt-5.5": {
"name": "GPT-5.5",
"limit": { "context": 128000, "output": 32768 }
},
"gemini-2.5-pro": {
"name": "Gemini 2.5 Pro",
"limit": { "context": 1000000, "output": 32768 }
}
}
}
}
}Two-provider trick: declare an Anthropic-flavored provider for Claude models (gets you Anthropic-only features like thinking + cache_control) and an OpenAI-compatible one for everything else.
Verify
bash
opencode
# In TUI:
/models # Pick a WRouter modelSend a test prompt.
Known limitations
- The OpenAI-compatible adapter does not pass Anthropic-specific fields. For Claude features, use the
wrouter-anthropicprovider. - 75+ supported providers from OpenCode mostly map to direct upstream endpoints; routing them through WRouter requires the
wrouterprovider entry as above.