OpenCode
OpenCode is a terminal AI coding agent. It reads providers from ~/.config/opencode/opencode.json (global) or opencode.json in the project root — a real config file, so the one-liner script below can set everything up for you.
1. Config
Merge into ~/.config/opencode/opencode.json and replace sk-og-... with your key:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"opusgate": {
"npm": "@ai-sdk/anthropic",
"name": "OpusGate",
"options": {
"baseURL": "https://api.opusgate.dev/v1",
"apiKey": "sk-og-..."
},
"models": {
"claude-opus-4.8": { "name": "Claude Opus 4.8" },
"claude-sonnet-4.6": { "name": "Claude Sonnet 4.6" },
"claude-haiku-4.5": { "name": "Claude Haiku 4.5" }
}
}
},
"model": "opusgate/claude-opus-4.8"
}The last line sets opusgate/claude-opus-4.8 as the default model, so OpenCode starts on OpusGate right away.
2. Or auto-install: one script does everything
Paste your key into the first line and run. Installs OpenCode if it's missing, then writes the config — an existing opencode.json is backed up to opencode.json.bak first.
KEY="sk-og-..." # ← your key from /keys
command -v opencode >/dev/null 2>&1 || curl -fsSL https://opencode.ai/install | bash
mkdir -p ~/.config/opencode
[ -f ~/.config/opencode/opencode.json ] && cp ~/.config/opencode/opencode.json ~/.config/opencode/opencode.json.bak
cat > ~/.config/opencode/opencode.json <<EOF
{
"\$schema": "https://opencode.ai/config.json",
"provider": {
"opusgate": {
"npm": "@ai-sdk/anthropic",
"name": "OpusGate",
"options": {
"baseURL": "https://api.opusgate.dev/v1",
"apiKey": "$KEY"
},
"models": {
"claude-opus-4.8": { "name": "Claude Opus 4.8" },
"claude-sonnet-4.6": { "name": "Claude Sonnet 4.6" },
"claude-haiku-4.5": { "name": "Claude Haiku 4.5" }
}
}
},
"model": "opusgate/claude-opus-4.8"
}
EOF
echo "Done — run 'opencode'."$KEY = "sk-og-..." # ← your key from /keys
if (-not (Get-Command opencode -ErrorAction SilentlyContinue)) { npm install -g opencode-ai }
$dir = "$env:USERPROFILE\.config\opencode"
New-Item -ItemType Directory -Force -Path $dir | Out-Null
if (Test-Path "$dir\opencode.json") { Copy-Item "$dir\opencode.json" "$dir\opencode.json.bak" -Force }
[IO.File]::WriteAllText("$dir\opencode.json", @"
{
"`$schema": "https://opencode.ai/config.json",
"provider": {
"opusgate": {
"npm": "@ai-sdk/anthropic",
"name": "OpusGate",
"options": {
"baseURL": "https://api.opusgate.dev/v1",
"apiKey": "$KEY"
},
"models": {
"claude-opus-4.8": { "name": "Claude Opus 4.8" },
"claude-sonnet-4.6": { "name": "Claude Sonnet 4.6" },
"claude-haiku-4.5": { "name": "Claude Haiku 4.5" }
}
}
},
"model": "opusgate/claude-opus-4.8"
}
"@)
Write-Host "Done - run 'opencode'."3. Run
Start opencode — it opens on the default model. Switch any time with /models → opusgate/claude-sonnet-4.6.
Troubleshooting
The JSON is invalid (usually a trailing comma) or the file is in the wrong place. OpenCode also picks up a project-local opencode.json which overrides the global one — check both.
401 → key mistyped or revoked (Keys); 402 → empty balance (top up). Full list: error codes.