Home → Guides → OpenCode with a custom API: config, Claude, small_model and real costs

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.

The config file

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": {}
      }
    }
  }
}
  1. Create a key in the console and set it as an environment variable, for example APICLAN_GPT_KEY.
  2. List only models from that key’s group under models. Each key on this gateway belongs to one group, so GPT, DeepSeek and Claude each need their own provider entry and key.
  3. Start opencode, type /models and pick APICLAN → gpt-6-astra. For scripts: opencode run -m apiclan/gpt-6-astra "...".
baseURLResult
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.

Adding Claude

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.

What one short reply costs

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.

ModelRequestsInput tokens (title + reply)Wall timeCost
gpt-6-astra24,640 + 7,67820.5 s$0.050
deepseek-v4-pro2528 + 5,70834.1 s$0.005
deepseek-v4.1-flash2529 + 3,02721.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.

Cut the overhead with small_model

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.

A small coding task

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.

ModelRequestsWall timeCostCorrectTest assertions
gpt-6-astra340 s$0.069✓2
deepseek-v4-pro361 s$0.008✓7
deepseek-v4.1-flash325 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.

Common errors

Other coding tools: Cline with a custom API · Codex with a custom API.

Start using it

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 quickstart

Language: 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.