OpenCode
Connect OpenCode to Yolo Router with Anthropic or OpenAI-compatible models.
- OpenCode is installed and available as
opencode. - A working Yolo Router endpoint, for example
https://api.yolorouter.com. - A Yolo Router API Key generated from the console.
- The model ID you want to use, for example
deepseek-v4-proorglm-5.1. It must exactly match the model ID in the Yolo Router console.
OpenCode supports both TUI and CLI modes. Its built-in
@ai-sdk/anthropicand@ai-sdk/openai-compatibleadapters can connect to Anthropic-protocol models and OpenAI-compatible models.
Option 1: Interactive Menu
Recommended for first-time setup.
Open the connect menu
In OpenCode, type:
/connectIn the provider list, choose Other or custom endpoint.
Fill in Yolo Router details
Enter:
| Field | Value |
|---|---|
| Base URL | https://api.yolorouter.com/v1 |
| API Key | your Yolo Router API Key |
After saving, type:
/modelsSwitch to the newly added provider and target model, then send a test message.
Option 2: Config File
Recommended for regular use, multiple pinned models, or per-project config.
Edit OpenCode config
Config file locations:
Global: ~/.config/opencode/opencode.json
Per-project: opencode.json in your project rootPer-project opencode.json takes precedence over the global config.
Add provider config
Add or merge the following config:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"yolorouter-anthropic": {
"npm": "@ai-sdk/anthropic",
"name": "Yolo Router (Anthropic)",
"options": {
"baseURL": "https://api.yolorouter.com/v1",
"apiKey": "sk-yolo-..."
},
"models": {
"glm-5.1": {
"name": "GLM 5.1",
"limit": { "context": 128000, "output": 8192 }
}
}
},
"yolorouter": {
"npm": "@ai-sdk/openai-compatible",
"name": "Yolo Router",
"options": {
"baseURL": "https://api.yolorouter.com/v1",
"apiKey": "sk-yolo-..."
},
"models": {
"deepseek-v4-flash": {
"name": "DeepSeek V4 Flash",
"limit": { "context": 131072, "output": 16384 }
},
"deepseek-v4-pro": {
"name": "DeepSeek V4 Pro",
"limit": { "context": 131072, "output": 16384 }
}
}
}
},
"model": "yolorouter/deepseek-v4-pro",
"autoshare": false
}Key fields:
yolorouter-anthropicuses@ai-sdk/anthropic; use it for Anthropic-protocol modelsyolorouteruses@ai-sdk/openai-compatible; use it for DeepSeek, GPT, and other OpenAI-compatible models- both providers use the same
baseURL:https://api.yolorouter.com/v1 apiKeyis embedded directly in the config in this example; replacesk-yolo-...with your real Yolo Router API Key- model keys under
modelsmust exactly match the model IDs exposed by the Yolo Router console - the top-level
modelfield sets the default model in<provider>/<model>format - to use a custom alias, add an
idfield pointing to the real model ID
Optional: manage keys via auth.json
If you do not want to store the API Key in opencode.json, remove options.apiKey and edit:
~/.local/share/opencode/auth.jsonWrite:
{
"yolorouter-anthropic": {
"type": "api",
"key": "sk-yolo-..."
},
"yolorouter": {
"type": "api",
"key": "sk-yolo-..."
}
}Or use the CLI:
opencode auth loginPick yolorouter-anthropic or yolorouter when prompted and paste your API Key.
Verify
Launch OpenCode:
opencodeType:
/modelsYou should see entries like:
yolorouter-anthropic/glm-5.1
yolorouter/deepseek-v4-proPick a model and send a test message. A normal response means the integration is working. You can also check the Yolo Router console for the request log.
Troubleshooting
Yolo Router models do not show in /models
Check that provider.yolorouter-anthropic.models or provider.yolorouter.models is populated and that the JSON format is valid. Restart OpenCode after changing config.
Model not found
Confirm that the model ID exactly matches the Yolo Router console. Do not use a display name, alias, or value with extra spaces.
Invalid API key
Verify options.apiKey in opencode.json, or the matching provider Key in auth.json. You can also re-run opencode auth login.
Anthropic models return protocol errors
Make sure you are calling the yolorouter-anthropic provider with @ai-sdk/anthropic, not the yolorouter provider with @ai-sdk/openai-compatible.
Config changes are not picked up
Restart OpenCode. If both global and per-project config files exist, the project-root opencode.json takes precedence.