Agents & Editors
OpenCode
Connecting OpenCode to an Adaptive Router through an OpenAI-compatible provider.
OpenCode is a coding agent for the terminal. It connects to Multi-Router through a custom provider built on the @ai-sdk/openai-compatible package, which sends OpenAI Chat Completions requests to an Adaptive Router with the router header.
Creating the router
OpenCode connects through an Adaptive Router, which accepts OpenAI Chat Completions requests and serves each one with the model it names, using the organization's provider key for that model's provider. OpenCode holds only the Multi-Router API key. See Adaptive Router. To set it up:
- In Model Groups, create or choose a model group with the models OpenCode should use. See Model Group.
- In Routers, choose New router, then Adaptive Router. Name it, choose the model group, and switch on the models to serve.
- Choose the organization's provider key for each provider in the group, and create the router. Its id, such as
rt_XXXXXXXX, is on the router's page. - In API Keys, create a key with the
inferencescope. It can be limited to this router. See API Key.
Every request carries the router id in the X-MR-Router header and the API key as a Bearer token, both set in OpenCode's settings below.
Settings
OpenCode reads ~/.config/opencode/opencode.json for every project, and opencode.json in a project for that project. Add a provider with the Multi-Router base URL, the API key from an environment variable, the router header and the models to offer:
Models
An Adaptive Router names models by their Multi-Router catalog id, provider/model, such as openai/gpt-5-nano, openai/gpt-5 or google/gemini-2.5-flash. The model must be switched on in the router's model group; a request for any other model is refused with a message listing the models the router serves. The settings on this page list each model id explicitly.
OpenCode names a model as the provider name followed by the model id, so openai/gpt-5-nano on the multi-router provider is multi-router/openai/gpt-5-nano, in the model setting, with -m, or in the model picker.
Checking the setup
The request then appears in Traffic with the Adaptive Router in the Router column and the model, tokens and cost in the request detail. A reply with the requested model or router was not found means the router id is wrong, or the API key is not allowed to use that router. See Traffic and Troubleshooting.