Skip to content

OpenCode: Claude and Codex configuration

Register CloudService as an OpenAI-compatible OpenCode provider and choose the model family that belongs to the key.

Automatic configuration

bash
npm install -g cloudservice@latest
cloudservice

Select OpenCode. The CLI detects the key's provider and billing mode, backs up ~/.config/opencode/opencode.json, stores the credential in a user-only file, and adds only models returned for that key. A Claude-only key is configured through the same OpenAI-compatible chat adapter with the Claude model IDs. Run cloudservice doctor to recheck the result.

Shared secure key setup

For manual setup, store the key outside JSON. Running this again replaces the OpenCode CloudService key, so do not switch between unrelated API-credit and token-pack accounts without also changing the URL:

bash
umask 077
mkdir -p "$HOME/.config/opencode"
printf "CloudService API key: "
IFS= read -r -s CLOUDSERVICE_API_KEY
printf "\n"
printf "%s\n" "$CLOUDSERVICE_API_KEY" > "$HOME/.config/opencode/cloudservice.key"
unset CLOUDSERVICE_API_KEY
chmod 600 "$HOME/.config/opencode/cloudservice.key"

Manual configuration for Codex models in OpenCode

Merge this provider into ~/.config/opencode/opencode.json. Preserve unrelated providers. For an OpenAI token-pack key, change only baseURL to https://api.yourdomain.example/token/v1.

json
{
  "$schema": "https://opencode.ai/config.json",
  "model": "cloudservice/gpt-5.6-terra",
  "small_model": "cloudservice/gpt-5.4-mini",
  "provider": {
    "cloudservice": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "CloudService Codex",
      "options": {
        "baseURL": "https://api.yourdomain.example/v1",
        "apiKey": "{file:~/.config/opencode/cloudservice.key}"
      },
      "models": {
        "codex-auto-review": { "name": "Codex Auto Review" },
        "gpt-5.3-codex": { "name": "GPT 5.3 Codex" },
        "gpt-5.4": { "name": "GPT 5.4" },
        "gpt-5.4-mini": { "name": "GPT 5.4 Mini" },
        "gpt-5.5": { "name": "GPT 5.5" },
        "gpt-5.6-luna": { "name": "GPT 5.6 Luna" },
        "gpt-5.6-sol": { "name": "GPT 5.6 Sol" },
        "gpt-5.6-terra": { "name": "GPT 5.6 Terra" }
      }
    }
  }
}

OpenCode sends these through its OpenAI-compatible adapter. It does not become the native Codex CLI, and some Responses-only behavior may not exist in this client.

bash
opencode run --pure --model cloudservice/gpt-5.4-mini --format json "K"

Manual configuration for Claude models in OpenCode

Use this version for a key that exposes Claude models. For a Claude token-pack key, change only baseURL to https://api.yourdomain.example/token/v1.

json
{
  "$schema": "https://opencode.ai/config.json",
  "model": "cloudservice/claude-opus-5",
  "small_model": "cloudservice/claude-haiku-4-5-20251001",
  "provider": {
    "cloudservice": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "CloudService Claude",
      "options": {
        "baseURL": "https://api.yourdomain.example/v1",
        "apiKey": "{file:~/.config/opencode/cloudservice.key}"
      },
      "models": {
        "fable-5": { "name": "Fable 5", "limit": { "context": 1050000, "output": 4096 } },
        "claude-haiku-4-5-20251001": { "name": "Claude Haiku 4.5", "limit": { "context": 200000, "output": 4096 } },
        "claude-opus-4-6": { "name": "Claude Opus 4.6", "limit": { "context": 200000, "output": 4096 } },
        "claude-opus-4-7": { "name": "Claude Opus 4.7", "limit": { "context": 200000, "output": 4096 } },
        "claude-opus-4-8": { "name": "Claude Opus 4.8", "limit": { "context": 200000, "output": 4096 } },
        "claude-opus-5": { "name": "Claude Opus 5", "limit": { "context": 1000000, "output": 128000 } },
        "claude-sonnet-5": { "name": "Claude Sonnet 5", "limit": { "context": 200000, "output": 4096 } }
      }
    }
  }
}

Claude Opus 5 advertises its native 128000-token output limit. The older entries keep a conservative 4096-token client cap. Lower the Opus 5 value if you want a smaller per-response budget. This is Claude through OpenCode's OpenAI-compatible adapter, not Claude Code's native Anthropic Messages setup.

bash
opencode run --pure \
  --model cloudservice/claude-haiku-4-5-20251001 \
  --format json \
  "K"

Key and model boundaries

Use only models returned for the authenticated key. Never paste the key into committed JSON. The cloudservice/ prefix selects OpenCode's provider; CloudService receives the exact ID after the slash.

See OpenCode's custom-provider reference.