opencode
Use Router9 as a custom provider in opencode
opencode is an open-source, terminal-based AI coding agent. It talks to any OpenAI-compatible endpoint through the AI SDK, so you can add Router9 as a custom provider without any code changes.
Everything below was verified against opencode 1.18.x (opencode --version).
Model configuration
opencode reads configuration from opencode.json — either at the root of your project, or globally so every project inherits it:
| OS | Global config |
|---|---|
| macOS / Linux | ~/.config/opencode/opencode.json |
| Windows | %USERPROFILE%\.config\opencode\opencode.json |
Add Router9 as a custom provider. opencode loads the OpenAI-compatible adapter from npm on first use, points it at Router9's base URL, and lists the models you want to route:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"router9": {
"npm": "@ai-sdk/openai-compatible",
"name": "Router9",
"options": {
"baseURL": "https://api.router9.com/v1",
"apiKey": "sk-r9k-your-key-here"
},
"models": {
"anthropic/claude-opus-5": { "name": "Claude Opus 5 (Router9)" },
"deepseek/deepseek-v4-flash": { "name": "DeepSeek v4 Flash (Router9)" }
}
}
}
}The model keys under models are the ids Router9 routes on — pull the exact set from GET /v1/models (see Choosing models). The name is only the label shown in opencode's model picker.
Keep your
sk-r9k-key in the global config (outside any repository) rather than a projectopencode.jsonyou might commit. The base URL is safe to commit; the key is not.
Running opencode
Non-interactive — name the provider and model as provider/model:
opencode run -m router9/anthropic/claude-opus-5 "Summarize the changes in this repo"Interactive TUI — just run opencode, then switch models with the /models
command and pick one under Router9.
To make Router9 the default so you can drop -m, set the top-level model:
{
"model": "router9/anthropic/claude-opus-5"
}Choosing models
Router9 model ids are provider-prefixed slugs, so short names like gpt-4o return 404 model_not_found. List what your deployment actually serves:
curl https://api.router9.com/v1/models \
-H "Authorization: Bearer sk-r9k-your-key-here"Put the ids you want under models in the config above. The exact set depends on your deployment — see Models.
If your administrator has configured an
autoroute you can add"auto": {}tomodelsand route on it.autois not a built-in alias — when no such route exists it returns404 model_not_found, so checkGET /v1/modelsfirst.
MCP Setup
opencode discovers MCP servers from the same opencode.json. Add Router9's hosted MCP server as a remote server to expose Router9 Skills as tools:
{
"mcp": {
"router9": {
"type": "remote",
"url": "https://api.router9.com/v1/mcp",
"enabled": true,
"headers": {
"Authorization": "Bearer sk-r9k-your-key-here"
}
}
}
}The Router9 tools (image_generate, memory_list, …) then appear to the agent. See Install MCP Server for the full tool list.
Skills (optional): Router9 also offers image and audio Skills as agent tools. MCP is the recommended way to expose them where your harness supports it; otherwise call them directly as REST endpoints (
/v1/image/*,/v1/audio/*,/v1/search/) with yoursk-r9k-key — see the API Reference.
Tips
- Router9's flat monthly pricing suits opencode's long, tool-heavy coding sessions — no per-token surprises.
- One
opencode.jsoncan register several providers; theprovider/modelprefix keeps them unambiguous. - Provider and MCP config share one file — a single global
opencode.jsonsets up both for every project.