OpenCode: connect a cheap AI API
OpenCode isn't tied to one provider: opencode.json takes any OpenAI-compatible endpoint. So one session can run on Claude and the next on GPT without changing anything but the model name.
OpenCode
Open-source terminal agent
Create an API key on the Keys page and copy it.
Install OpenCode:
npm install -g opencode-aiAdd the provider to opencode.json (project root, or global ~/.config/opencode/opencode.json):
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"cheapai": {
"npm": "@ai-sdk/openai-compatible",
"name": "CheapAI",
"options": {
"baseURL": "https://cheapai.io/v1",
"apiKey": "{env:CHEAPAI_API_KEY}"
},
"models": {
"claude-opus-4-8": { "name": "Claude Opus 4.8" },
"gpt-5.6-sol": { "name": "GPT-5.6 Sol" }
}
}
}
}Add any models you need from the catalog to the models map.
Export your key (macOS / Linux — add to ~/.zshrc for persistence):
export CHEAPAI_API_KEY="YOUR_API_KEY"Run opencode, then /models — pick a model under CheapAI.
Replace YOUR_API_KEY with a real key from the Keys section.
OpenCode — common questions
Where does OpenCode keep its config?
opencode.json in the project root, or globally at ~/.config/opencode/opencode.json. The project one wins.
Can I keep several models?
Yes — list them under the provider's models and switch inside the session; the key and base URL stay the same.
Get a key and plug it into OpenCode
Claude, GPT, Gemini and Grok on one key · pay in ₽, USDT or by card · no VPN
Get API keyGuides for other tools
See also: model prices · API reference and FAQ