OpenCode
Install OpenCode, add OneRouter through the OpenAI-compatible provider package, and verify model selection and tool access.
Managing multiple providers?
CC-Switch can manage OpenCode provider entries visually. Configure OpenCode directly once first, then follow the CC-Switch guide if you need frequent switching.
Install OpenCode
Use the official install script or your existing package manager. Reopen the terminal if opencode is not immediately available.
curl -fsSL https://opencode.ai/install | bashStore the API key
Keep API keys in environment variables or the client's protected credential store. Never commit keys to a project, paste them into chat, or include them in screenshots.
export ONEROUTER_API_KEY="YOUR_ONEROUTER_API_KEY"Configure the provider
Create or edit the user OpenCode configuration. The provider uses @ai-sdk/openai-compatible, the base URL stops at /v1, and model keys use complete OneRouter slugs. Environment interpolation keeps the secret out of the JSON file.
Replace every <MODEL_SLUG> occurrence with the same complete ID from Text & Chat Models or GET /v1/models.
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"onerouter": {
"npm": "@ai-sdk/openai-compatible",
"name": "OneRouter",
"options": {
"baseURL": "https://onerouter.com/v1",
"apiKey": "{env:ONEROUTER_API_KEY}"
},
"models": {
"<MODEL_SLUG>": {
"name": "<MODEL_SLUG>"
}
}
}
},
"model": "onerouter/<MODEL_SLUG>"
}Launch and choose a model
Start OpenCode in a familiar repository, open /models, and confirm the OneRouter provider and configured models appear. Begin with a read-only request before allowing edits or commands.
cd <PROJECT_PATH>
opencodeTroubleshooting
| Symptom | How to fix it |
|---|---|
OneRouter does not appear in /models | Validate the JSON file path and syntax, then fully restart OpenCode. |
| 401 | Confirm ONEROUTER_API_KEY exists in the OpenCode process and environment interpolation is unchanged. |
| 404 | Use https://onerouter.com/v1; do not append /chat/completions in baseURL. |
| Model not found | Make the provider model key and default-model suffix match the complete OneRouter slug exactly. |
| Tools or images fail | Select a model that supports the required capability and retest with a minimal prompt. |