Agent Tools

OpenCode

Connect OpenCode to Yolo Router with Anthropic or OpenAI-compatible models.

iBefore you start
  • OpenCode is installed and available as opencode.
  • A working Yolo Router endpoint, for example https://api.yolorouter.com.
  • A Yolo Router API Key generated from the console.
  • The model ID you want to use, for example deepseek-v4-pro or glm-5.1. It must exactly match the model ID in the Yolo Router console.

OpenCode supports both TUI and CLI modes. Its built-in @ai-sdk/anthropic and @ai-sdk/openai-compatible adapters can connect to Anthropic-protocol models and OpenAI-compatible models.

Option 1: Interactive Menu

Recommended for first-time setup.

Launch OpenCode

Open your project directory and run:

opencode

Open the connect menu

In OpenCode, type:

/connect

In the provider list, choose Other or custom endpoint.

Fill in Yolo Router details

Enter:

FieldValue
Base URLhttps://api.yolorouter.com/v1
API Keyyour Yolo Router API Key

After saving, type:

/models

Switch to the newly added provider and target model, then send a test message.

Option 2: Config File

Recommended for regular use, multiple pinned models, or per-project config.

Edit OpenCode config

Config file locations:

Global: ~/.config/opencode/opencode.json
Per-project: opencode.json in your project root

Per-project opencode.json takes precedence over the global config.

Add provider config

Add or merge the following config:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "yolorouter-anthropic": {
      "npm": "@ai-sdk/anthropic",
      "name": "Yolo Router (Anthropic)",
      "options": {
        "baseURL": "https://api.yolorouter.com/v1",
        "apiKey": "sk-yolo-..."
      },
      "models": {
        "glm-5.1": {
          "name": "GLM 5.1",
          "limit": { "context": 128000, "output": 8192 }
        }
      }
    },
    "yolorouter": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Yolo Router",
      "options": {
        "baseURL": "https://api.yolorouter.com/v1",
        "apiKey": "sk-yolo-..."
      },
      "models": {
        "deepseek-v4-flash": {
          "name": "DeepSeek V4 Flash",
          "limit": { "context": 131072, "output": 16384 }
        },
        "deepseek-v4-pro": {
          "name": "DeepSeek V4 Pro",
          "limit": { "context": 131072, "output": 16384 }
        }
      }
    }
  },
  "model": "yolorouter/deepseek-v4-pro",
  "autoshare": false
}

Key fields:

  • yolorouter-anthropic uses @ai-sdk/anthropic; use it for Anthropic-protocol models
  • yolorouter uses @ai-sdk/openai-compatible; use it for DeepSeek, GPT, and other OpenAI-compatible models
  • both providers use the same baseURL: https://api.yolorouter.com/v1
  • apiKey is embedded directly in the config in this example; replace sk-yolo-... with your real Yolo Router API Key
  • model keys under models must exactly match the model IDs exposed by the Yolo Router console
  • the top-level model field sets the default model in <provider>/<model> format
  • to use a custom alias, add an id field pointing to the real model ID

Optional: manage keys via auth.json

If you do not want to store the API Key in opencode.json, remove options.apiKey and edit:

~/.local/share/opencode/auth.json

Write:

{
  "yolorouter-anthropic": {
    "type": "api",
    "key": "sk-yolo-..."
  },
  "yolorouter": {
    "type": "api",
    "key": "sk-yolo-..."
  }
}

Or use the CLI:

opencode auth login

Pick yolorouter-anthropic or yolorouter when prompted and paste your API Key.

Verify

Launch OpenCode:

opencode

Type:

/models

You should see entries like:

yolorouter-anthropic/glm-5.1
yolorouter/deepseek-v4-pro

Pick a model and send a test message. A normal response means the integration is working. You can also check the Yolo Router console for the request log.

Troubleshooting

Yolo Router models do not show in /models

Check that provider.yolorouter-anthropic.models or provider.yolorouter.models is populated and that the JSON format is valid. Restart OpenCode after changing config.

Model not found

Confirm that the model ID exactly matches the Yolo Router console. Do not use a display name, alias, or value with extra spaces.

Invalid API key

Verify options.apiKey in opencode.json, or the matching provider Key in auth.json. You can also re-run opencode auth login.

Anthropic models return protocol errors

Make sure you are calling the yolorouter-anthropic provider with @ai-sdk/anthropic, not the yolorouter provider with @ai-sdk/openai-compatible.

Config changes are not picked up

Restart OpenCode. If both global and per-project config files exist, the project-root opencode.json takes precedence.

On this page