Setup guide

Connect OpenCode

OpenCode is an open-source coding agent for the terminal. You add CheapTokens as a custom provider in opencode.json.

Before you start

The snippets below use claude-sonnet-5-5. Pick another model to update them.

Windows

  1. Install OpenCode with npm. You need Node.js first.
    PowerShell
    npm install -g @opencode/cli
  2. Save your key as an environment variable. Close PowerShell and open it again so the new variables load.
    PowerShell
    setx CHEAPTOKENS_API_KEY "YOUR_API_KEY"
  3. Create the file %USERPROFILE%\.config\opencode\opencode.json with this content. To use it for one project only, save it as opencode.json in that project's folder instead.
    opencode.json
    {
      "$schema": "https://opencode.ai/config.json",
      "model": "cheaptokens/claude-sonnet-5-5",
      "provider": {
        "cheaptokens": {
          "npm": "@ai-sdk/openai-compatible",
          "name": "CheapTokens",
          "options": {
            "baseURL": "https://cheaptokens.pw/v1",
            "apiKey": "{env:CHEAPTOKENS_API_KEY}"
          },
          "models": {
            "claude-sonnet-5-5": { "name": "claude-sonnet-5-5", "limit": { "context": 200000, "output": 8192 } }
          }
        }
      }
    }
  4. Run opencode in your project folder. Type /models to confirm CheapTokens is selected, then send a message.

macOS

  1. Install OpenCode.
    Terminal
    curl -fsSL https://opencode.ai/v2/install | bash
  2. Save your key as an environment variable. The last line reloads your shell settings, so the variables work straight away.
    Terminal
    echo 'export CHEAPTOKENS_API_KEY="YOUR_API_KEY"' >> ~/.zshrc
    source ~/.zshrc
  3. Create the file ~/.config/opencode/opencode.json with this content. To use it for one project only, save it as opencode.json in that project's folder instead.
    opencode.json
    {
      "$schema": "https://opencode.ai/config.json",
      "model": "cheaptokens/claude-sonnet-5-5",
      "provider": {
        "cheaptokens": {
          "npm": "@ai-sdk/openai-compatible",
          "name": "CheapTokens",
          "options": {
            "baseURL": "https://cheaptokens.pw/v1",
            "apiKey": "{env:CHEAPTOKENS_API_KEY}"
          },
          "models": {
            "claude-sonnet-5-5": { "name": "claude-sonnet-5-5", "limit": { "context": 200000, "output": 8192 } }
          }
        }
      }
    }
  4. Run opencode in your project folder. Type /models to confirm CheapTokens is selected, then send a message.

Linux

  1. Install OpenCode.
    Terminal
    curl -fsSL https://opencode.ai/v2/install | bash
  2. Save your key as an environment variable. The last line reloads your shell settings, so the variables work straight away.
    Terminal
    echo 'export CHEAPTOKENS_API_KEY="YOUR_API_KEY"' >> ~/.bashrc
    source ~/.bashrc
  3. Create the file ~/.config/opencode/opencode.json with this content. To use it for one project only, save it as opencode.json in that project's folder instead.
    opencode.json
    {
      "$schema": "https://opencode.ai/config.json",
      "model": "cheaptokens/claude-sonnet-5-5",
      "provider": {
        "cheaptokens": {
          "npm": "@ai-sdk/openai-compatible",
          "name": "CheapTokens",
          "options": {
            "baseURL": "https://cheaptokens.pw/v1",
            "apiKey": "{env:CHEAPTOKENS_API_KEY}"
          },
          "models": {
            "claude-sonnet-5-5": { "name": "claude-sonnet-5-5", "limit": { "context": 200000, "output": 8192 } }
          }
        }
      }
    }
  4. Run opencode in your project folder. Type /models to confirm CheapTokens is selected, then send a message.

Check that it works

Send a short message in OpenCode, then open Dashboard → Usage. The request appears there within a few seconds, with its model, tokens and cost.

Good to know

If something goes wrong

What you seeWhat to do
401 or invalid_api_keyThe key is wrong, disabled or has extra spaces. Create a new key and paste it again.
402 or insufficient_quotaYour balance is empty. Top up under Billing.
404 or model_not_foundThe model ID has a typo. Copy it from the models page.
404 on every requestThe base URL is wrong. Check whether this tool needs the /v1 ending (see the steps above).
429Too many requests per minute. Wait a few seconds and retry.

Prefer a guided version? Open the setup wizard →