Router9
Documentation
Integrations

opencode

Use Router9 as a custom provider in opencode

opencode logo

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:

OSGlobal 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 project opencode.json you 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 auto route you can add "auto": {} to models and route on it. auto is not a built-in alias — when no such route exists it returns 404 model_not_found, so check GET /v1/models first.

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 your sk-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.json can register several providers; the provider/model prefix keeps them unambiguous.
  • Provider and MCP config share one file — a single global opencode.json sets up both for every project.

On this page