Home → Guides → OpenCode with a custom API: config, Claude, small_model and real costs
OpenCode reads its providers from opencode.json, so the setup is one file. What surprised us was the bill: asking OpenCode to reply with a single word sent two requests and over 12,000 input tokens. We ran OpenCode 1.19.0 against our gateway with three models to show where the tokens go and how to cut them.
Put this in ~/.config/opencode/opencode.json (or opencode.json in your project):
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"apiclan": {
"npm": "@ai-sdk/openai-compatible",
"name": "APICLAN",
"options": {
"baseURL": "https://apiclan.us/v1",
"apiKey": "{env:APICLAN_GPT_KEY}"
},
"models": {
"gpt-6-astra": {},
"gpt-6.1-sol": {}
}
}
}
}
APICLAN_GPT_KEY.models. Each key on this gateway belongs to one group, so GPT, DeepSeek and Claude each need their own provider entry and key.opencode, type /models and pick APICLAN → gpt-6-astra. For scripts: opencode run -m apiclan/gpt-6-astra "...".| baseURL | Result |
|---|---|
https://apiclan.us/v1 | ✓ |
https://apiclan.us | ✗ 404 Not Found |
@ai-sdk/openai-compatible appends /chat/completions to baseURL and nothing else, so the /v1 has to be there. Without it OpenCode stops with a bare Not Found.
Add a second provider inside provider, using the Anthropic package and a key from a Claude group:
"claude": {
"npm": "@ai-sdk/anthropic",
"name": "APICLAN Claude",
"options": {
"baseURL": "https://apiclan.us/v1",
"apiKey": "{env:APICLAN_CLAUDE_KEY}"
},
"models": { "claude-fable-5-1": {} }
}
Here too baseURL must end in /v1: the Anthropic package only appends /messages, and https://apiclan.us alone returned 404 in our test. That is the opposite of Claude Code, whose ANTHROPIC_BASE_URL must not contain /v1.
We asked OpenCode to “Reply with just OK” in an empty project. Every model needed two requests: one to write a title for the session, and the real one, which carries OpenCode’s system prompt and tool definitions.
| Model | Requests | Input tokens (title + reply) | Wall time | Cost |
|---|---|---|---|---|
gpt-6-astra | 2 | 4,640 + 7,678 | 20.5 s | $0.050 |
deepseek-v4-pro | 2 | 528 + 5,708 | 34.1 s | $0.005 |
deepseek-v4.1-flash | 2 | 529 + 3,027 | 21.8 s | $0.0006 |
OpenCode sends GPT models a much longer system prompt (about 7,700 tokens) than DeepSeek (about 3,000), and the title request on GPT alone used 4,640 tokens. That is why the same “OK” cost about 77 times more on gpt-6-astra than on deepseek-v4.1-flash. Tested 12 October 2026 on OpenCode 1.19.0; costs are what our gateway billed.
OpenCode uses small_model for side jobs such as session titles. Point it at a cheap model in its own provider:
"small_model": "apiclan-ds/deepseek-v4.1-flash",
"provider": {
"apiclan": { ... },
"apiclan-ds": {
"npm": "@ai-sdk/openai-compatible",
"options": {
"baseURL": "https://apiclan.us/v1",
"apiKey": "{env:APICLAN_DS_KEY}"
},
"models": { "deepseek-v4.1-flash": {} }
}
}
With gpt-6-astra as the main model, the title request dropped from $0.0187 to $0.00003, and the whole one-word exchange from $0.050 to $0.031 — 38% less on every new session, with no change to the answers.
Same task for each model: write fizzbuzz.py and pytest tests for it, without running commands. We then checked each function against the correct output for 1–30.
| Model | Requests | Wall time | Cost | Correct | Test assertions |
|---|---|---|---|---|---|
gpt-6-astra | 3 | 40 s | $0.069 | ✓ | 2 |
deepseek-v4-pro | 3 | 61 s | $0.008 | ✓ | 7 |
deepseek-v4.1-flash | 3 | 25 s | $0.0011 | ✓ | 7 |
All three wrote correct code in three requests. deepseek-v4.1-flash was the fastest and cost about 1/60 of gpt-6-astra; both DeepSeek models also wrote more thorough tests. deepseek-v4-pro was the slowest because it reasons before each step. Wall time includes OpenCode’s own start-up of a few seconds.
baseURL without /v1.apiKey is not set in the shell that starts OpenCode.is not supported by any configured account in this group) → a model under models that is not in the key’s group — for example a GPT model listed under a provider that uses a DeepSeek key.Other coding tools: Cline with a custom API · Codex with a custom API.
No subscription, no monthly minimum, no sales call. Top up with USDT and spend what you use — 1 USDT gives you 2 credits of API balance.
Read the 30-second quickstartLanguage: English · 简体中文 · 繁體中文 · 日本語 · 한국어 · Deutsch · Français · Español · Türkçe · Português · Italiano · Bahasa Indonesia · Tiếng Việt · Bahasa Melayu · Polski · Čeština · فارسی · Русский
Prices on this page are filled in automatically from live billing data. Third-party terms are quoted from that party's own documentation.