Route OpenCode Through an LLM Router (and Where Claude Code Fits)
Coding agents send a lot of requests: a title, a plan, then a long run of tool calls. When the model behind them returns 429 halfway through a refactor, the session stalls. Putting a router between the agent and your providers gives you one endpoint, one key, and automatic failover to another model or provider. This guide shows a tested setup for OpenCode and other OpenAI-compatible tools, then explains what Claude Code needs from a gateway, which is a different API.
As of 2026-10-20. Tested with OpenCode 1.19.3.
Which API each tool speaks
| Tool | API it calls | What a router has to expose |
|---|---|---|
| OpenCode | Any AI SDK provider. Custom providers use @ai-sdk/openai-compatible (/v1/chat/completions) | OpenAI-compatible Chat Completions |
| Aider, Continue, Cline, Roo Code, and most "OpenAI-compatible" settings | OpenAI Chat Completions | OpenAI-compatible Chat Completions |
| Claude Code | Anthropic Messages (/v1/messages), or Bedrock/Vertex/Foundry formats | An Anthropic-format endpoint |
That last row is the important one. Claude Code connects to "any gateway that exposes a supported API format", and those formats are Anthropic's, not OpenAI's. Anthropic also says it "doesn't support routing Claude Code to non-Claude models through any gateway."
OpenCode + SentioGate (tested)
SentioGate is an OpenAI-compatible router. Your provider keys (OpenRouter, OpenAI, Gemini, Groq, Mistral, DeepSeek, xAI) live in its encrypted Vault, you send model: "auto", and when a model rate-limits or fails it moves to the next key or model and remembers the cooldown.
1. Get a SentioGate API key (sg_live_...) from the dashboard, and export it:
export SENTIOGATE_API_KEY="sg_live_..."
2. Add the provider to opencode.json (in your project, or ~/.config/opencode/opencode.json):
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"sentiogate": {
"npm": "@ai-sdk/openai-compatible",
"name": "SentioGate",
"options": {
"baseURL": "https://api.sentiogate.dev/v1",
"apiKey": "{env:SENTIOGATE_API_KEY}"
},
"models": {
"auto": { "name": "SentioGate auto (failover)" },
"openrouter/anthropic/claude-sonnet-4": { "name": "Claude Sonnet 4 via OpenRouter key" }
}
}
},
"model": "sentiogate/auto",
"small_model": "sentiogate/auto"
}
autoroutes across the models you've enabled in your Vault and fails over between them.provider/model(for examplegroq/llama-3.3-70b-versatile) pins a specific model on your own key. SentioGate splits on the first/, so OpenRouter IDs keep their own slash:openrouter/anthropic/claude-sonnet-4.- Setting
small_modelkeeps OpenCode's background tasks, such as session titles, on your router too. Without it, OpenCode uses its own default small model for those.
3. Run it:
opencode run "Reply with exactly the word pong and nothing else."
# > build · auto
# pong
We ran exactly this against the live API (OpenCode 1.19.3). The build agent's request carries OpenCode's tool definitions and came back normally. The first run takes longer, because OpenCode installs the @ai-sdk/openai-compatible package.
What happens on a 429 mid-session
With your own keys, a 429 puts that model on that key into a shared cooldown (it honors the provider's Retry-After, capped at 2 minutes), and the request moves to your next key for the same model, then (with auto) to the next model in your pool. OpenRouter's daily free-model cap is recognized and parks all :free models on that key until 00:00 UTC. If nothing is left, OpenCode gets a fast 429 with a Retry-After header instead of a hung request.
Agent sessions are long, so a model switch partway through is a real trade-off. If you need one model throughout, pin a provider/model instead of auto. Pinned models get key failover only (add a second key for that provider) and are never swapped for a different model.
Trying it with no provider keys
A SentioGate key with no provider keys uses the community pool. During the beta that's a single model shared by everyone (150 requests per 5 hours per user), with no failover. It's enough to check the wiring. Coding agents burn through requests quickly, though, so add your own keys for real work.
Other OpenAI-compatible tools
The same three values work in any tool that has an "OpenAI-compatible" setting:
| Setting | Value |
|---|---|
| Base URL | https://api.sentiogate.dev/v1 |
| API key | your sg_live_... key |
| Model | auto, or provider/model |
For example, Aider documents OPENAI_API_BASE + OPENAI_API_KEY with an openai/ model prefix:
export OPENAI_API_BASE=https://api.sentiogate.dev/v1
export OPENAI_API_KEY=$SENTIOGATE_API_KEY
aider --model openai/auto
(We tested only the OpenCode and SDK paths live. Check other tools against their own docs.)
Claude Code: what you need, and what SentioGate doesn't do yet
Claude Code reads ANTHROPIC_BASE_URL plus a gateway credential (see Connect Claude Code to an LLM gateway). The gateway has to speak the Anthropic Messages API and forward the headers Claude Code relies on, which are listed in Anthropic's gateway compatibility guide.
SentioGate doesn't expose /v1/messages today, so you can't point Claude Code at it. We'd rather say so than suggest a workaround that breaks halfway through a session. If you need Claude Code behind a gateway now, gateways that document Anthropic-format support include LiteLLM's Claude Code tutorial and Anthropic's own Claude apps gateway. Keep in mind Anthropic's note that routing Claude Code to non-Claude models isn't supported by Anthropic.
Two related details, so nobody is surprised:
- Claude models through SentioGate today go through OpenRouter. Add an OpenRouter key and use
openrouter/anthropic/<model>. A direct Anthropic API key isn't forwarded by the router yet. - OpenCode can still use Claude, through the OpenRouter route above, with failover around it.
Troubleshooting
| Symptom | Likely cause |
|---|---|
401 invalid_api_key | SENTIOGATE_API_KEY isn't exported in the shell that runs opencode. |
403 no_enabled_models | auto found no enabled models in your Vault. Enable at least one model. |
403 community_pool_disabled_with_byok | You asked for sentiogate-community while provider keys are saved. Use auto or provider/model, or remove the keys to use the community pool. |
429 upstream_rate_limited with Retry-After | Every candidate model is cooling down. Wait the stated seconds, or add another key or provider. |
| Model not found in OpenCode | The model key in opencode.json must match what you send (auto, or provider/model). Run curl -s https://api.sentiogate.dev/v1/models -H "Authorization: Bearer $SENTIOGATE_API_KEY" to list models. |
Sources
- OpenCode, Providers: Custom provider (last updated 2026-10-19, accessed 2026-10-20)
- Anthropic, Claude Code: Other LLM gateways (accessed 2026-10-20)
- Aider, OpenAI-compatible APIs
- LiteLLM, Claude Code tutorial
- SentioGate API reference