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
- A CheapTokens account with some balance. Create one if you haven't.
- Your API key from Dashboard → API key. It starts with
ct_live_. - Any text model from the models page. They all work over the OpenAI Chat Completions format.
The snippets below use claude-sonnet-5-5. Pick another model to update them.
Windows
-
Install OpenCode with npm. You need Node.js first.PowerShell
npm install -g @opencode/cli
-
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"
-
Create the file
%USERPROFILE%\.config\opencode\opencode.jsonwith this content. To use it for one project only, save it asopencode.jsonin 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 } } } } } } -
Run
opencodein your project folder. Type/modelsto confirm CheapTokens is selected, then send a message.
macOS
-
Install OpenCode.Terminal
curl -fsSL https://opencode.ai/v2/install | bash
-
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
-
Create the file
~/.config/opencode/opencode.jsonwith this content. To use it for one project only, save it asopencode.jsonin 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 } } } } } } -
Run
opencodein your project folder. Type/modelsto confirm CheapTokens is selected, then send a message.
Linux
-
Install OpenCode.Terminal
curl -fsSL https://opencode.ai/v2/install | bash
-
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
-
Create the file
~/.config/opencode/opencode.jsonwith this content. To use it for one project only, save it asopencode.jsonin 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 } } } } } } -
Run
opencodein your project folder. Type/modelsto 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
- This config uses OpenCode's classic format, which both the current (V2) and older versions read.
- List every model you want under
models. Pick between them inside OpenCode with/models. - OpenCode needs a model that supports tool calling.
If something goes wrong
| What you see | What to do |
|---|---|
401 or invalid_api_key | The key is wrong, disabled or has extra spaces. Create a new key and paste it again. |
402 or insufficient_quota | Your balance is empty. Top up under Billing. |
404 or model_not_found | The model ID has a typo. Copy it from the models page. |
| 404 on every request | The base URL is wrong. Check whether this tool needs the /v1 ending (see the steps above). |
| 429 | Too many requests per minute. Wait a few seconds and retry. |
Prefer a guided version? Open the setup wizard →