Skip to content

Configure OpenCode's Router One provider and model IDs

OpenCode is the open-source terminal coding agent from Anomaly, with a TUI, a desktop app and IDE extensions, and it takes custom model providers straight from opencode.jsonc (or opencode.json). One native V2 provider block using @opencode/ai/providers/openai-compatible pointed at https://api.router.one/v1 can put the Claude, GPT, Gemini, Grok and DeepSeek chat models in its /models picker behind one key (the picker lists the IDs you declare in the block). Each model turn, subagent task and session title the gateway forwards to a model reaches Router One as POST /v1/chat/completions and appears in Dashboard → Logs (requests refused before any model is called have no record, and a streamed turn that failed before any output may have no record either), and a maxSpend cap on the key is the hard stop on wallet charges for sessions that run unattended. A custom provider's models match nothing in OpenCode's models.dev catalog, so the block also has to declare each model's real context window and input capabilities — and pick a cheaper model for session titles. Checked against OpenCode 2.4.2 (released 2026-11-26, @opencode/cli on npm) on 2026-11-27, per the opencode.ai docs and the v2.4.2 source.

Install OpenCode 2.x and store the key

OpenCode 2.x is the stable default line: install v2.4.2 with npm install -g @opencode/cli, curl -fsSL https://opencode.ai/v2/install | bash, or brew install anomalyco/tap/opencode-v2 (per the V1 migration guide, remove any package-managed V1 opencode-ai install first because both ship the opencode binary). Create a Router One key for OpenCode alone and give it a maxSpend cap on wallet charges: an agent session sends one request per model turn, including turns that only return a tool result, so a long session can send many metered requests (wallet charge or plan quota). Top up with a card, Alipay or WeChat Pay through hosted checkout, or with USDT/USDC on six chains (Tron, BSC, Ethereum, Polygon, Base, Arbitrum). No US credit card required. Supply the key either by exporting ROUTER_ONE_API_KEY and listing "env": ["ROUTER_ONE_API_KEY"] in the provider block (since v2.4.1, config-only providers list their models in /models without running /connect), or by storing it with /connect (or /login / /auth) in the TUI under the same provider ID, which writes ~/.local/share/opencode/auth.json; opencode auth list shows stored credentials.

terminal
npm install -g @opencode/cli      # OpenCode 2.4.2 on npm as of 2026-11-27
export ROUTER_ONE_API_KEY=sk-your-router-one-key
opencode                          # optional: /connect → store key under router-one
opencode auth list                # show stored credentials

Configure OpenCode to use the Router One base URL

Define the provider under providers in ~/.config/opencode/opencode.jsonc (or opencode.json) for every project, or in a project's opencode.jsonc / opencode.json, which OpenCode merges on top of the global file. The key under providers is the provider ID (router-one below) and must match /connect if you store credentials there. Set package to @opencode/ai/providers/openai-compatible for OpenCode's native Chat Completions client (which appends /chat/completions to settings.baseURL; aisdk:@ai-sdk/openai-compatible also works). Set settings.baseURL to https://api.router.one/v1, list ROUTER_ONE_API_KEY in env, and declare each exact catalog ID under models. Select a model as router-one/<catalog-id> in /models, or pin it with the top-level model field:

opencode.jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "model": "router-one/anthropic/claude-sonnet-5",
  "agents": {
    "title": { "model": "router-one/anthropic/claude-haiku-4.5" }
  },
  "providers": {
    "router-one": {
      "name": "Router One",
      "env": ["ROUTER_ONE_API_KEY"],
      "package": "@opencode/ai/providers/openai-compatible",
      "settings": { "baseURL": "https://api.router.one/v1" },
      "models": {
        "anthropic/claude-sonnet-5": {
          "name": "Claude Sonnet 5",
          "capabilities": { "tools": true, "input": ["text", "image"], "output": ["text"] },
          "limit": { "context": 1000000, "output": 32000 }
        },
        "anthropic/claude-haiku-4.5": {
          "name": "Claude Haiku 4.5",
          "capabilities": { "tools": true, "input": ["text", "image"], "output": ["text"] },
          "limit": { "context": 200000, "output": 16000 }
        },
        "deepseek-v4-flash": {
          "name": "DeepSeek V4 Flash",
          "capabilities": { "tools": true, "input": ["text"], "output": ["text"] },
          "limit": { "context": 1000000, "output": 32000 }
        }
      }
    }
  }
}

Set real limits and image capabilities per Router One model

For a model defined only in your config, OpenCode v2.4.2 fills in defaults from its source (packages/schema/src/model.ts): capabilities { tools: true, input: ["text", "image"], output: ["text"] } and limit { context: 200000, output: 32000 }. That creates two traps if you leave them out. First, a 1M-window model compacts early around 200,000 tokens unless you set limit.context explicitly from the model's page on /models (rounded down to a whole number: 1000000 for anthropic/claude-sonnet-5, openai/gpt-5.6-sol and deepseek-v4-flash; 200000 for anthropic/claude-haiku-4.5). Second, OpenCode assumes image input is supported by default: on a text-only ID such as deepseek-v4-flash, explicitly set capabilities.input to ["text"], otherwise pasting a screenshot sends an image and the gateway returns HTTP 400 with has no chat candidate that supports requested capabilities: vision. A larger window lets OpenCode send longer prompts: on a plan, a request whose input exceeds a model's long-context threshold draws more than one plan request (see /pricing).

Pin the session-title model with agents.title.model

OpenCode generates a title for each session with its built-in title agent. When no title model is set, OpenCode first looks for a small model on the same provider and otherwise uses your main model — often the most expensive ID you run. In OpenCode 2.x, set agents.title.model to a cheaper catalog ID on the same provider, such as router-one/anthropic/claude-haiku-4.5 (replacing V1's small_model, which V2 still normalizes automatically). Title requests forwarded to a model then appear in Dashboard → Logs under that cheaper ID.

Claude IDs on /v1/messages, GPT-6 IDs on /v1/responses (optional)

The @opencode/ai/providers/openai-compatible block already serves every chat model on /v1/chat/completions (for tool-calling agent sessions on Chat Completions, pick non-GPT-6 models such as anthropic/claude-sonnet-5, openai/gpt-5.6-sol, deepseek-v4-flash or grok-4.7). For the native Messages API on Claude-family or DeepSeek V4 IDs, add a second provider under a different ID with package set to @opencode/ai/providers/anthropic-compatible and settings.baseURL set to https://api.router.one/v1: per the v2.4.2 source, that client appends /messages and sends x-api-key, which Router One accepts. To send models to /v1/responses — required for tool calling on GPT-6 Astra, GPT-6.1 and GPT-6.2 models such as openai/gpt-6.2-sol per OpenAI's GPT-6 / GPT-6.2 guides (GPT-6 Sol supports Chat Completions function calling only with reasoning_effort set to none) — use package @opencode/ai/providers/openai-compatible/responses (on a dedicated provider or per-model override) with settings.baseURL https://api.router.one/v1; use it only for IDs whose model page lists POST /v1/responses (GPT-family, DeepSeek and Grok chat models). A Claude-family ID sent to /v1/responses returns HTTP 400 model '<id>' must be called via /v1/messages or /v1/chat/completions, and Gemini IDs are not served there either.

Run one prompt, check timeouts and match it in Logs

opencode models prints every provider/model OpenCode loaded (in v2.4.2 it takes no provider argument, so pipe to grep router-one to filter), which is the fastest check that your config parsed. opencode run -m router-one/anthropic/claude-sonnet-5 "Reply with OK" sends one non-interactive prompt. In Dashboard → Logs, each request the gateway forwards to a model appears under the catalog ID with its tokens, wallet charge or plan quota used, status, total time and, for a streamed turn that produced output, time to first token (TTFT); a title request may follow under the agents.title.model ID. Requests refused before any model is called (401, 402, key/account 429, or 400/404 for the model ID or endpoint) have no log row, and a streamed turn that failed before any output may have no log row either. A 401 usually means ROUTER_ONE_API_KEY was not exported in the shell that launched opencode or the /connect provider ID differs from the key under providers. Per the v2.4.2 source (packages/core/src/provider.ts), provider settings default to headerTimeout 300000 ms (5 minutes) and chunkTimeout 900000 ms (15 minutes), with settings.timeout unset by default (applying to every request type when set since v2.4.0), and per OpenCode's providers docs, timed-out requests retry up to three times.

terminal
opencode models | grep router-one
opencode run -m router-one/anthropic/claude-sonnet-5 "Reply with OK"

Upgrading from OpenCode 1.x (legacy opencode-ai)

Legacy OpenCode 1.x remains on the opencode-ai npm package (1.19.6 as of 2026-11-27). Per the official V1 migration guide (opencode.ai/docs/migrate-v1/), OpenCode 2.x reads the same opencode.json locations and normalizes supported V1 provider blocks in memory without rewriting your file: provider maps to providers, npm maps to package (for example aisdk:@ai-sdk/openai-compatible, alongside the native @opencode/ai/providers/openai-compatible), options.baseURL maps to settings.baseURL, small_model maps to agents.title.model, and limit.context / limit.output carry over (V1's attachment field is ignored with a warning). Keep each provider entry entirely in one format, and keep a V1 backup before converting to native V2 syntax, because OpenCode 1.x cannot read a native V2 config file.

Which model ID should OpenCode send?

Copy the exact model ID from /models, preserving case, hyphens, and version suffixes; do not substitute a display name. Open its detail page and match the supported API endpoints, context window, and capabilities such as tool calling to the provider and features selected in OpenCode. A catalog listing does not mean the client can use every feature of that model. Give each client or application a dedicated API key with a maxSpend cap. A key's spend cap (maxSpend) limits what that key can charge to your wallet: once its cumulative wallet charges reach the cap, its wallet-billed requests return HTTP 402. Requests covered by your plan's quota draw from the account's shared plan quota and do not count toward any key's cap.

Which API protocol is OpenCode using?

OpenAI-compatible describes an interface format; it does not make Chat Completions (/v1/chat/completions), Responses (/v1/responses), and Anthropic Messages (/v1/messages) interchangeable. Check the installed client version, provider configuration, and actual request path against the model detail page and API compatibility fact sheet. A successful plain-text chat does not establish support for hosted tools, conversation state, or file-editing features.

Verify the OpenCode call in your request trace

Send a simple text request from OpenCode, then match its trace in Dashboard → Logs by time, model, and request_id: tokens, the wallet charge or plan quota it used, latency, and status. Next, test streaming, tool calls, and multi-turn history separately. For failures, retain the actual request path, full error message, and request_id. If there is no matching log, either the request never reached the gateway (client configuration or connectivity) or the gateway refused it before calling a model — a 401 for the key, a 402 for funds, a 429 from your key's or account's limits, or a 400 or 404 for the model ID or endpoint; a streamed request that failed before any output may have no log either. The status and error message the client received tell which, so check them before attributing the error to the gateway or upstream.

FAQ

Why does OpenCode report the model as unknown or fail to authenticate?

Check three things in order. The provider ID in the model string must match the key under providers (router-one/<catalog-id>). Every model must be listed in that provider's models map with the exact ID from /models. And the key must resolve: exported in the variable listed under env (ROUTER_ONE_API_KEY) in the shell that launches opencode, stored under the same provider ID with /connect, or passed through a V1 {env:ROUTER_ONE_API_KEY} reference (which becomes an empty string rather than an error if unset).

Why does a long session compact around 200K tokens, or fail with a vision 400 on a text-only model?

Because OpenCode v2.4.2 defaults unknown models to limit.context 200,000, limit.output 32,000, and capabilities.input ["text", "image"]. Set limit.context explicitly to the model page's window (rounded down to a whole number, such as 1000000 for 1M models) so compaction uses the real window, and set capabilities.input to ["text"] on text-only IDs such as deepseek-v4-flash so screenshots are not sent.

Why do session titles run on my most expensive model?

Because agents.title.model is unset and a custom provider gives OpenCode no cheaper built-in model to pick, so titles fall back to the main model. Set agents.title.model to a cheaper catalog ID on the same provider, for example router-one/anthropic/claude-haiku-4.5.

Can OpenCode use Router One's Anthropic-compatible endpoint or Responses API?

Yes, optionally. The default @opencode/ai/providers/openai-compatible block serves every chat model on /v1/chat/completions. For native /v1/messages on Claude-family and DeepSeek V4 IDs, add a second provider with package @opencode/ai/providers/anthropic-compatible and settings.baseURL https://api.router.one/v1 (Router One accepts the x-api-key header it sends). For /v1/responses — required for tool calling on GPT-6 Astra, GPT-6.1 and GPT-6.2 models such as openai/gpt-6.2-sol (GPT-6 Sol supports Chat Completions function calling only with reasoning_effort set to none) — use @opencode/ai/providers/openai-compatible/responses on IDs whose model page lists POST /v1/responses. Keep separate providers under distinct IDs.

Does an existing OpenCode 1.x opencode.json still work in OpenCode 2.4?

Per the OpenCode V1 migration guide, yes: OpenCode 2.x reads the same config paths and normalizes supported V1 provider, npm, options.baseURL and small_model fields in memory without rewriting the file (V1's attachment field is ignored with a warning). Keep a V1 backup before converting to native V2 syntax (providers, package, settings.baseURL, capabilities, agents.title.model), because 1.x cannot read native V2 config.

Which OpenCode version is this guide for?

Checked on 2026-11-27 against OpenCode 2.4.2 (released 2026-11-26, @opencode/cli on npm), per the opencode.ai docs and the v2.4.2 source, with V1 migration notes covering legacy opencode-ai 1.19.6. Model defaults and timeout values come directly from the v2.4.2 source; re-check them after major upgrades.

Which models can OpenCode use through the gateway?

Choose a current catalog model that supports both the endpoint and the features OpenCode uses. Check /models and the model detail page for the exact ID, current rates, and capabilities; a family name such as GPT or Claude is not a compatibility guarantee. A client that lists a model has only read the ID, from its own configuration or from GET /v1/models; verify an actual request too.

Models are listed, but requests fail with 400 or 404. What should I check?

Record the actual request path and error message, then check the exact model ID. A 400 can indicate invalid parameters, unsupported tools, or a model/endpoint mismatch; a 404 can indicate an incorrect path or missing resource, so it does not by itself establish that a model was retired. If the error says must be called via, use the named endpoint or select a model supported on the current endpoint. Do not add or remove /v1 or /chat/completions across all clients indiscriminately.

Does this work from Mainland China?

Yes. The gateway is reachable from Mainland China without a VPN, and the configuration is identical to the global setup.

How do I debug a 401/402/403/429?

Start from what your client received: the status, the error body and the X-Request-ID header. A 401 (missing, unknown, revoked or expired key), a 402 (wallet balance, or the key's maxSpend cap) and a 429 from your key's or account's rate limits are refused before any model is called, so they never appear in Dashboard → Logs — nor does a 400 or 404 for a wrong model ID or endpoint. For 401, check that the full key is sent and still active in Dashboard → API Keys; for 402, top up or raise the key's maxSpend; for a 403, keep the full error body. For 429, back off and retry later; a 429 that does show up in Logs came back from upstream after the gateway's retries. Keep the request_id and follow the error-codes reference.