1. Prepare your API key
Create a CheapLLM key and export it in the environment that starts OpenCode. Keep the secret out of the config file and out of the repository. Note that the CheapLLM site is still a demonstration and the API does not accept requests yet; the configuration below is the target setup.
export CHEAPLLM_API_KEY="YOUR_CHEAPLLM_API_KEY"
2. Add the provider
Register an OpenAI-compatible provider in opencode.json (or opencode.jsonc). In OpenCode 2 providers live under the providers object: package selects the OpenAI-compatible runtime and settings.baseURL sets the API endpoint. The file stores the environment variable name, never the key itself. On OpenCode 1 use the second form instead, where the same values are named provider, npm and options.baseURL.
{
"$schema": "https://opencode.ai/config.json",
"providers": {
"cheapllm": {
"name": "CheapLLM",
"env": ["CHEAPLLM_API_KEY"],
"package": "@opencode/ai/providers/openai-compatible",
"settings": {
"baseURL": "https://api.cheapllm.com/v1"
},
"models": {
"MODEL_ID": { "name": "MODEL_ID" }
}
}
}
}
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"cheapllm": {
"npm": "@ai-sdk/openai-compatible",
"name": "CheapLLM",
"options": {
"baseURL": "https://api.cheapllm.com/v1",
"apiKey": "{env:CHEAPLLM_API_KEY}"
},
"models": {
"MODEL_ID": { "name": "MODEL_ID" }
}
}
}
}
3. Choose a model
Replace MODEL_ID with an identifier from your CheapLLM catalog and set it as the default model in the same configuration file.
{
"model": "cheapllm/MODEL_ID"
}
4. Verify the connection
Start OpenCode in the terminal where the key is exported. Open the model list with /models, select CheapLLM and send a short test prompt.
opencode
/models
