Skip to content

OpenCode

OpenCode is an open-source terminal AI coding agent with TUI / CLI modes. It bundles @ai-sdk/anthropic and @ai-sdk/openai-compatible adapters, so WRouter's Anthropic and OpenAI endpoints both work out of the box.

Prerequisites

ItemRequirement
OpenCodeInstalled
WRouterA working sk- token
  1. Launch OpenCode TUI
  2. Type /connect
  3. Pick Other (custom endpoint)
  4. Fill in:
    • Base URL: https://wrouter.ai/v1
    • API Key: sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  5. Save; switch model with /models

Config locations (project-level overrides global):

  • Global: ~/.config/opencode/opencode.json
  • Project: opencode.json at the project root
json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "wrouter-anthropic": {
      "npm": "@ai-sdk/anthropic",
      "name": "wrouter (Anthropic)",
      "options": {
        "baseURL": "https://wrouter.ai/v1",
        "apiKey": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
      },
      "models": {
        "claude-sonnet-4-6": {
          "name": "Claude Sonnet 4.6",
          "limit": { "context": 200000, "output": 8192 }
        },
        "haiku": {
          "id": "claude-haiku-4-5",
          "name": "Claude Haiku 4.5 (fast)",
          "limit": { "context": 200000, "output": 8192 }
        }
      }
    },
    "wrouter": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "wrouter",
      "options": {
        "baseURL": "https://wrouter.ai/v1",
        "apiKey": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
      },
      "models": {
        "gpt-5.5": {
          "name": "GPT-5.5",
          "limit": { "context": 128000, "output": 32768 }
        },
        "gemini-2.5-pro": {
          "name": "Gemini 2.5 Pro",
          "limit": { "context": 1000000, "output": 32768 }
        }
      }
    }
  }
}

Two-provider trick: declare an Anthropic-flavored provider for Claude models (gets you Anthropic-only features like thinking + cache_control) and an OpenAI-compatible one for everything else.

Verify

bash
opencode
# In TUI:
/models  # Pick a WRouter model

Send a test prompt.

Known limitations

  • The OpenAI-compatible adapter does not pass Anthropic-specific fields. For Claude features, use the wrouter-anthropic provider.
  • 75+ supported providers from OpenCode mostly map to direct upstream endpoints; routing them through WRouter requires the wrouter provider entry as above.