OpenCode setup

OpenCode is an open-source terminal coding agent. Copy the config below, add your key, and use Claude and GPT inside OpenCode.

Updated 2026-11-16

1. Get an API key

Sign up in the TokenMilo console, top up and create a key under API Keys.

2. Install OpenCode

# macOS / Linux
curl -fsSL https://opencode.ai/v2/install | bash

# or with npm
npm install -g @opencode/cli

On Windows, download the standalone zip or desktop app from the OpenCode website. Uninstall V1 first if you had it.

3. Add the config

Create or edit ~/.config/opencode/opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "model": "tokenmilo-claude/claude-sonnet-5-5",
  "providers": {
    "tokenmilo-claude": {
      "name": "TokenMilo Claude",
      "package": "@opencode/ai/providers/anthropic-compatible",
      "settings": { "baseURL": "https://api.tokenmilo.com/v1", "apiKey": "{env:TOKENMILO_API_KEY}" },
      "models": {
        "claude-sonnet-5-5": { "name": "Claude Sonnet 5.5", "limit": { "context": 200000, "output": 32000 } },
        "claude-opus-5-5": { "name": "Claude Opus 5.5", "limit": { "context": 200000, "output": 32000 } },
        "claude-haiku-5-5": { "name": "Claude Haiku 5.5", "limit": { "context": 200000, "output": 32000 } }
      }
    },
    "tokenmilo-gpt": {
      "name": "TokenMilo GPT",
      "package": "@opencode/ai/providers/openai-compatible",
      "settings": { "baseURL": "https://api.tokenmilo.com/v1", "apiKey": "{env:TOKENMILO_API_KEY}" },
      "models": {
        "gpt-6.1-sol": { "name": "GPT-6.1 Sol", "limit": { "context": 200000, "output": 32000 } }
      }
    }
  }
}

Mind the URLs: the Claude provider uses https://api.tokenmilo.com/v1 (with /v1); the GPT provider uses https://api.tokenmilo.com/v1.

4. Set the key and run

export TOKENMILO_API_KEY=sk-your-tokenmilo-key   # add to ~/.zshrc or ~/.bashrc
opencode

Windows:

setx TOKENMILO_API_KEY "sk-your-tokenmilo-key"   # then reopen the terminal
opencode

Type /models to see the TokenMilo models, ask something, then check Usage Logs in the console.

5. Troubleshooting

  • 404 — the Claude baseURL is missing /v1, or the model ID is wrong (see the model list).
  • 401 — the environment variable isn’t set in this shell, or the key is incomplete.
  • Config ignored — check the JSON is valid and uses the V2 keys providers / package / settings.

FAQ

Why does the Claude URL include /v1 here?

OpenCode’s Anthropic-compatible provider only appends /messages, so the base URL must be https://api.tokenmilo.com/v1 — the opposite of Claude Code.

Older tutorials use provider / npm / options — which is right?

OpenCode V2 renamed them: provider → providers, npm → package, options → settings. Use the format on this page for current versions.

Can I avoid putting the key in an environment variable?

Yes. Remove the apiKey line, start OpenCode, type /connect, choose TokenMilo Claude or TokenMilo GPT and paste your key.

Related guides

Need an API key?

Sign up at TokenMilo, top up, and create a key in the console in under a minute.

Get API key See all models