Run OpenCode Against AnyRouter

Point OpenCode at AnyRouter so sessions are billed once, logged, and can use any Chat Completions model.

OpenCode speaks Chat Completions, and AnyRouter exposes a compatible /api/v1 endpoint. Sessions draw from one balance (or your BYOK accounts), appear in your request logs, and catalog context windows flow into OpenCode's limit.context and limit.output.

With the CLI

anyr opencode

The first run asks you to paste an sk-ar- key or log in at anyrouter.dev, then saves your profile to ~/.anyrouter/config.yaml. Pin a model per session; auto lets your pinned preset choose, and anything after -- goes to OpenCode:

anyr opencode --model "anthropic/claude-sonnet-4-6"
anyr opencode --model auto -- --help

Persistent config

Register AnyRouter in ~/.config/opencode/opencode.json so a bare opencode uses it. Export ANYROUTER_API_KEY first (create a key in the dashboard), then pick anyrouter/… in /models.

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "anyrouter": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "AnyRouter",
      "options": {
        "baseURL": "https://anyrouter.dev/api/v1",
        "apiKey": "{env:ANYROUTER_API_KEY}"
      },
      "models": {
        "anthropic/claude-sonnet-4-6": {
          "name": "Claude Sonnet 4.6",
          "limit": { "context": 200000, "output": 65536 }
        }
      }
    }
  },
  "model": "anyrouter/anthropic/claude-sonnet-4-6"
}

After the first prompt, the row in request logs confirms the session billed through AnyRouter.

Run non-OpenAI models, for example GLM with your own Z-AI key: anyr opencode --model "z-ai/glm-5.2". List compatible models at anyrouter.dev/models?endpoint=chat-completions.

AnyRouter routes requests to third-party models. Models and outputs are provided as is, with no warranty; you use them at your own risk. Disclaimer