Skip to main content
Connecting OpenCode to BetterToken is done by editing the config file. BetterToken is compatible with the Anthropic SDK format.

Prerequisites

Install OpenCode

curl -fsSL https://opencode.ai/install | bash

Setup

1

Clear conflicting environment variables

unset ANTHROPIC_AUTH_TOKEN
unset ANTHROPIC_BASE_URL
2

Edit the OpenCode config file

Config file location: ~/.config/opencode/opencode.jsonAdd the following (replace YOUR_API_KEY):
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "bettertoken": {
      "npm": "@ai-sdk/anthropic",
      "options": {
        "baseURL": "https://www.bettertoken.com/v1",
        "apiKey": "YOUR_API_KEY"
      },
      "models": {
        "claude-sonnet-4-5": {
          "name": "claude-sonnet-4-5"
        }
      }
    }
  }
}
3

Start OpenCode

cd /path/to/your/project
opencode
4

Select the model

Type /models inside OpenCode and select claude-sonnet-4-5.

Add more models

Add multiple models to the models field in the config:
"models": {
  "claude-sonnet-4-5": { "name": "claude-sonnet-4-5" },
  "claude-opus-4-5":   { "name": "claude-opus-4-5" },
  "claude-haiku-4-5":  { "name": "claude-haiku-4-5" }
}