OpenCode
Route OpenCode through BitRouter by adding it as an OpenAI-compatible provider in opencode.json.
OpenCode registers providers through opencode.json using the AI SDK. Add BitRouter as an OpenAI-compatible provider and the terminal agent routes across the whole registry.
Prerequisites
-
BitRouter running — local proxy at
http://127.0.0.1:4356, or BitRouter Cloud athttps://api.bitrouter.ai. -
OpenCode installed:
curl -fsSL https://opencode.ai/install | bash # or: npm install -g opencode-ai
Point OpenCode at BitRouter
Add a provider block to opencode.json (project root or ~/.config/opencode/opencode.json). baseURL points at the /v1 root; the model keys are the registry ids you want to expose.
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"bitrouter": {
"npm": "@ai-sdk/openai-compatible",
"name": "BitRouter",
"options": {
"baseURL": "http://127.0.0.1:4356/v1",
"apiKey": "{env:BITROUTER_API_KEY}"
},
"models": {
"openai/gpt-4o": { "name": "GPT-4o via BitRouter" },
"anthropic/claude-sonnet-4-6": { "name": "Claude Sonnet 4.6 via BitRouter" }
}
}
}
}opencodePick a model
Each key under models is a registry id in provider/model form, optionally with a :cost / :latency variant. Select one in the TUI, or run opencode run --model bitrouter/openai/gpt-4o. See Models.
Learn more
How is this guide?