EasyRouterEasyRouter
Quick StartAPI DocsConnect Agent Tools

OpenCode

OpenCode tutorial โ€” Open-source terminal AI coding agent compatible with 75+ providers. Connect to EasyRouter via interactive menu or config file using the OpenAI-compatible API.

Project Introduction

OpenCode is an open-source terminal AI coding agent with both TUI and CLI modes. It's compatible with 75+ AI service providers and, via its built-in @ai-sdk/anthropic and @ai-sdk/openai-compatible adapters, can seamlessly connect to both Anthropic-protocol models and OpenAI-compatible models served by EasyRouter.

๐Ÿ“ฆ Prerequisites

What you'll need

  • OpenCode installed
  • An EasyRouter endpoint (must end with /v1)
  • An EasyRouter API key (generated in the console)
  • A model ID exactly matching one exposed by your EasyRouter console (e.g. claude-sonnet-4-6, claude-haiku-4-5, deepseek-v4-pro, gpt-5.5)

Add EasyRouter directly from the OpenCode TUI:

  1. Launch the OpenCode TUI
  2. Type /connect
  3. In the provider list, choose "Other" (custom endpoint)
  4. Fill in:
    • Base URL: https://easyrouter.io/v1
    • API Key: your EasyRouter API key
  5. After saving, type /models and switch to the newly added model

Good for pinning multiple models and reusing across projects.

1. Edit OpenCode config

File location:

  • Global: ~/.config/opencode/opencode.json
  • Per-project (takes precedence): opencode.json in your project root
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "easyrouter-anthropic": {
      "npm": "@ai-sdk/anthropic",
      "name": "EasyRouter (Anthropic)",
      "options": {
        "baseURL": "https://easyrouter.io/v1",
        "apiKey": "sk-123"
      },
      "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 }
        }
      }
    },
    "easyrouter": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "EasyRouter",
      "options": {
        "baseURL": "https://easyrouter.io/v1",
        "apiKey": "sk-123"
      },
      "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 }
        },
        "gpt-5.5": {
          "name": "GPT-5.5",
          "limit": { "context": 128000, "output": 32768 }
        },
        "gpt-5.4": {
          "name": "GPT-5.4",
          "limit": { "context": 128000, "output": 32768 }
        },
        "gpt-5.4-mini": {
          "name": "GPT-5.4 Mini",
          "limit": { "context": 128000, "output": 16384 }
        }
      }
    }
  },
  "model": "easyrouter-anthropic/claude-sonnet-4-6",
  "autoshare": false
}

Key fields

  • The example declares two providers:
    • easyrouter-anthropic: npm must be @ai-sdk/anthropic โ€” use this for Claude and other Anthropic-protocol models
    • easyrouter: npm must be @ai-sdk/openai-compatible โ€” use this for DeepSeek, GPT, and other OpenAI-compatible models
  • Both providers share the same baseURL: https://easyrouter.io/v1
  • apiKey is embedded directly in the config file โ€” replace sk-123 with your real EasyRouter API key (the example value is a placeholder)
  • Model IDs under models must exactly match the model names exposed by your EasyRouter console. You can use a custom alias by adding an id field pointing to the real model (see haiku โ†’ claude-haiku-4-5 in the example)
  • The top-level model field sets the default model in the form <provider>/<model>
  • Per-project opencode.json takes precedence over the global config

2. Configure the API key

The example above already embeds the API key directly in opencode.json via options.apiKey. Just replace sk-123 with your real EasyRouter key โ€” no extra step required.

Optional: manage keys via auth.json

If you'd rather not store the API key in opencode.json, remove the apiKey field from the config and edit ~/.local/share/opencode/auth.json instead:

{
  "easyrouter-anthropic": {
    "type": "api",
    "key": "sk-your-easyrouter-key"
  },
  "easyrouter": {
    "type": "api",
    "key": "sk-your-easyrouter-key"
  }
}

Or use the CLI:

opencode auth login

Pick easyrouter-anthropic and/or easyrouter when prompted and paste your API key.

โœ… Step 3: Verify

Launch OpenCode and type /models. You should see entries like easyrouter-anthropic/claude-sonnet-4-6 and easyrouter/deepseek-v4-pro. Pick a model and send a test message โ€” a normal response means you're set.

โ“ Troubleshooting

IssueFix
EasyRouter models don't show in /modelsCheck that provider.easyrouter-anthropic.models or provider.easyrouter.models is populated
Model not foundConfirm the model ID matches your EasyRouter console exactly
Invalid API keyVerify apiKey in opencode.json or your auth.json; or re-run opencode auth login
Claude models return protocol errorsMake sure you're calling the easyrouter-anthropic provider (@ai-sdk/anthropic), not easyrouter (@ai-sdk/openai-compatible)
Config changes not picked upRestart OpenCode; per-project config wins over global