OpenCode is one of the most popular open-source coding agents — a terminal-first tool, provider-agnostic by design. Through the AI SDK and Models.dev it supports dozens of providers out of the box, and for anything it doesn’t list, you can wire up a custom provider in a few lines. That makes it a natural home for cheap models like DeepSeek, GLM, Kimi, and Qwen.
This covers the config that connects any OpenAI-compatible endpoint, where the files live, and the small things that go wrong. For why you’d run a cheaper backend at all, see use cheap AI models with Claude Code — the cost logic carries straight over.
Two ways to add a provider
OpenCode supports many providers natively. For an OpenAI-compatible one, you have two paths:
- Quick:
opencode auth login, scroll to Other, paste your key and base URL. - Explicit: define a custom provider in the config — clearer, reproducible, and version-controllable.
The config approach is worth knowing because it pins exact model IDs and base URLs.
Install OpenCode
npm install -g opencode-ai
On Windows it works directly, but WSL gives the cleaner shell — see install OpenCode on Windows with WSL and the WSL install guide.
Add a custom provider
OpenCode reads a global config (commonly ~/.config/opencode/opencode.json) and a project-level opencode.json. A custom DeepSeek provider using the OpenAI-compatible SDK looks like this:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"deepseek": {
"npm": "@ai-sdk/openai-compatible",
"name": "DeepSeek",
"options": {
"baseURL": "https://api.deepseek.com/v1",
"apiKey": "{env:DEEPSEEK_API_KEY}"
},
"models": {
"deepseek-chat": { "name": "DeepSeek Chat" },
"deepseek-reasoner": { "name": "DeepSeek Reasoner" }
}
}
}
}
The {env:DEEPSEEK_API_KEY} syntax pulls the key from your environment instead of hard-coding it. Export it first:
export DEEPSEEK_API_KEY="sk-your-key"
Other providers
Same structure, different endpoint. Qwen via Alibaba’s international OpenAI-compatible URL:
{
"provider": {
"dashscope": {
"npm": "@ai-sdk/openai-compatible",
"name": "Qwen",
"options": {
"baseURL": "https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
"apiKey": "{env:DASHSCOPE_API_KEY}"
},
"models": { "qwen3-coder-plus": { "name": "Qwen3 Coder Plus" } }
}
}
}
Custom provider fields
| npm | @ai-sdk/openai-compatible for OpenAI-style APIs |
|---|---|
| name | Display name |
| options.baseURL | The provider's /v1 endpoint |
| options.apiKey | {env:VAR} reads from your environment |
| models | Map of model IDs OpenCode can use |
For per-model specifics, see DeepSeek + OpenCode, GLM + OpenCode, Kimi K2.5 Turbo + OpenCode, and MiniMax M2 + OpenCode.
Pick the model and run
Set a default model in the config or choose it in the TUI:
{
"model": "deepseek/deepseek-chat"
}
Then launch:
opencode
The model identifier is always provider/model, matching your config keys.
Troubleshooting
- Provider not found — the
providerkey and themodelprefix must match exactly (deepseek↔deepseek/...). - Auth failures — the
{env:...}variable isn’t set in the shell that launched OpenCode. - Wrong base URL — most providers expect the
/v1suffix; confirm on their docs. - Model ID rejected — pull the current model name from the provider; IDs change between releases.
OpenCode custom provider checklist
- Install OpenCode (npm i -g opencode-ai)
- Add a provider block with @ai-sdk/openai-compatible
- Set baseURL and apiKey via {env:VAR}
- List the model IDs you'll use
- Set a default model and launch with opencode
Wrapping up
OpenCode runs on any cheap model through one config pattern: a custom provider using @ai-sdk/openai-compatible, with the base URL, an {env:...} API key, and your model list. Set a default provider/model and launch. The same block works for DeepSeek, Qwen, GLM, Kimi, and local servers — only the URL and IDs change.
For the bigger landscape, see best cheap Claude Code alternatives for Windows and the head-to-head in Claude Code vs Codex vs OpenCode vs Aider.