Heabsy Code from $20/mo · See plans →

OpenCode on Qwen3.8 27B: Custom Provider, Costs and a Measured Task

by

Published:

OpenCode adds any OpenAI-compatible API through a provider block in opencode.json: the base URL https://api.heabsy.com/v1, the model with its limits, and a cost block with the cached-input price, so OpenCode's cost display matches the bill. The context limit also decides when OpenCode compacts a session (at the limit minus up to 32,000 tokens). On a small Python task (five failing tests, error handling, one new test) OpenCode 1.19.5 on Qwen3.8 27B cost $0.054 and $0.062 in two runs at our catalog prices on 8 November 2026.

OpenCode is an open-source coding agent for the terminal. It reads and edits files, runs commands and loops until the task is done, and every turn of that loop is one request to the model. It ships with a list of providers, and any other OpenAI-compatible API can be added in a few lines of opencode.json.

This tutorial adds Qwen3.8 27B on our API as a custom provider, makes OpenCode’s cost display match what you are billed, explains which limit decides when OpenCode compacts a long session, and runs one small task twice with every model call logged.

How do you add a custom provider to OpenCode?

Put a provider block in opencode.json: in the project root for one project, or in ~/.config/opencode/opencode.json for all of them.

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "heabsy": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Heabsy",
      "options": { "baseURL": "https://api.heabsy.com/v1" },
      "models": {
        "qwen38": {
          "name": "Qwen3.8 27B",
          "limit": { "context": 200000, "output": 32768 },
          "cost": { "input": 1.05, "output": 3.15, "cache_read": 0.08 }
        },
        "mimo-v26-flash": {
          "name": "MiMo V2.6 Flash",
          "limit": { "context": 1048576, "output": 65536 },
          "cost": { "input": 0.50, "output": 1.50, "cache_read": 0.20 }
        }
      }
    }
  },
  "model": "heabsy/qwen38"
}

Then store the key and pick the model:

  1. Run /connect, choose Other, enter the provider ID heabsy and paste your key. OpenCode keeps it in ~/.local/share/opencode/auth.json, outside the repository. For CI, put "apiKey": "{env:HEABSY_API_KEY}" into options instead; in our runs that worked in a project-level opencode.json.
  2. Run /models and choose Heabsy › Qwen3.8 27B. The model’s full name is heabsy/qwen38.
  3. Ask OpenCode to read one file of your project. A correct answer means the connection and tool calling work; the request also appears in the Logs page of your console.

How do you make OpenCode’s cost display match your bill?

OpenCode prices a custom model only from its cost block, in dollars per million tokens. Without it every request shows as $0, and both of our runs below showed exactly that. Unlike Cline, OpenCode takes a price for cached input (cache_read), and in agent work most of the input is cached: in our runs 75–88% of it came from the prompt cache, billed at $0.08 per million on Qwen3.8 27B against $1.05 for fresh input.

With the block in place OpenCode counts correctly. In a separate check, the cost it reported for a request was exactly the tokens times the prices we had entered, reasoning tokens included. With --format json, every step_finish event carries the tokens (fresh input, cached input, output, reasoning) and the cost of that step.

What did one task cost?

The task was a small Python module of our own, not an issue from a public project: durations.py turns strings like "2h30m" into seconds, and 5 of its 8 pytest tests failed (days, spaces between number and unit, upper-case units, a bare number, all of them together). OpenCode got one instruction: make all tests pass without changing them, add error handling for invalid input and one new test for it. We ran OpenCode 1.19.5 twice on 4 November 2026, each time on a clean copy:

opencode run --auto --format json -m heabsy/qwen38 "Make all tests pass without changing them; add error handling for invalid input and one new test for it."

--auto approves every action without asking. Afterwards we ran pytest ourselves, checked that the original tests were untouched and fed the parser invalid input.

Run 1 Run 2
Result 9 passed, tests untouched, 1 new test 9 passed, tests untouched, 1 new test
Model calls / tool calls 12 / 13 9 / 12
Input tokens, of them cached 158,658, 140,380 (88%) 92,738, 69,519 (75%)
Output tokens, of them reasoning 9,973, 7,979 (80%) 7,576, 6,023 (80%)
Largest single request 18,700 tokens 15,215 tokens
Cost at catalog prices $0.0618 $0.0538
Wall-clock time 68 s 60 s

Both runs added days, case-insensitive units, spaces and bare numbers, and raise ValueError on input such as "", "abc", "5x" or "2h-5m" (on None they raise TypeError). One of the model calls in each run is not an agent step: OpenCode also asks the model for a session title, about 600 tokens without tools.

Where the $0.0618 of the first run went:

  • Fresh input, $0.0192. 18,278 tokens: the first request and the new part of each later one.
  • Cached input, $0.0112. 140,380 tokens of conversation that each request repeated from the one before.
  • Output, $0.0314, of which reasoning $0.0251. Qwen3.8 27B thinks before each tool call, and that thinking is billed as output; OpenCode sends no parameter to turn it off.

The same task in Cline, with its own numbers, is in Cline on Qwen3.8 27B.

Get an API key and run OpenCode on your own code: Qwen3.8 27B is free for 7 days, no card. After that you pay per token, and your first top-up gets $5 extra. Free requests run at lower priority at peak times.

Which limit decides when OpenCode compacts?

Every call sends the whole session again, so a call costs more as the session grows. OpenCode 1.19.5 compacts (summarises the older part and continues from the summary) when the session reaches limit.context minus the output reserve: limit.output or 32,000 tokens, whichever is smaller. Without limit.context there is no automatic compaction, and a long session runs until the API rejects it.

So limit.context is also a ceiling on what one call can cost. Cost of one call at the compaction point, with 88% of the input cached and 1,000 tokens of output as in the runs above:

limit.context Compacts at Qwen3.8 27B MiMo V2.6 Flash
131,072 99,072 tokens $0.0226 $0.0249
200,000 168,000 tokens $0.0361 $0.0411
1,048,576 (full window) 1,016,576 tokens $0.2028 $0.2414

The largest request in our runs was 18,700 tokens and cost about $0.0068, so compaction never came near. The config above sets 200,000 for Qwen3.8 27B: compaction then fires at 168,000 tokens and no call costs much over $0.036. Each compaction rewrites the history, so the call after it is billed at the fresh-input price; raise the limit if sessions compact too often for your work. MiMo V2.6 Flash keeps its full window in the example. The cost formula behind these numbers is in What an agent step costs.

What goes wrong, and how do you fix it?

Symptom Fix
Heabsy does not appear in /models OpenCode is not reading the file, or the block has no npm field. Check the location and validate against the $schema.
404 Not Found baseURL must be exactly https://api.heabsy.com/v1.
The session cost shows $0 Add the cost block to the model, with cache_read.
Long sessions fail with a context error Add limit.context and limit.output; without them OpenCode does not compact.
Model not found Use the catalog ID as the key under models (qwen38, mimo-v26-flash).

Where does your code go?

From OpenCode on your machine straight to api.heabsy.com. Qwen3.8 27B and MiMo V2.6 Flash run on GPUs we operate in the European Economic Area, and prompts and completions are not stored; we keep what billing needs: the model, the token counts and the time. The setup reference with the full model table is on the OpenCode integration page.

Method

  • Prices: our model catalog on 8 November 2026 (Qwen3.8 27B): $1.05 input, $0.08 cached input, $3.15 output per million tokens.
  • Runs: OpenCode 1.19.5, model qwen38 on https://api.heabsy.com/v1, two runs on clean copies of the same module, in parallel with other coding agents on 4 November 2026 between 10:02 and 10:13 UTC.
  • Counting: every request went through a logging proxy to our API; tokens are from the usage block of each response, cost is tokens times catalog prices. OpenCode was also checked directly against the API without the proxy.
  • Checks: pytest after each run, a comparison of the original tests before and after, and a separate set of invalid inputs the agent had not seen.

FAQ

How do I add a custom OpenAI-compatible provider to OpenCode?+
Add a provider block to opencode.json with `"npm": "@ai-sdk/openai-compatible"`, the base URL in `options.baseURL` and the models under `models`, each with `limit.context` and `limit.output`. Store the key with `/connect` (choose Other and enter the same provider ID) or reference an environment variable as `{env:HEABSY_API_KEY}`, and pick the model with `/models`.
Why does OpenCode show $0 for my custom model?+
OpenCode prices a custom model only from its `cost` block. Without it every request shows as $0, which is what both of our runs showed. Add `cost` with `input`, `output` and `cache_read` in dollars per million tokens: for Qwen3.8 27B on our API that is 1.05, 3.15 and 0.08 at catalog prices on 8 November 2026.
When does OpenCode compact the conversation?+
In OpenCode 1.19.5, when a session reaches `limit.context` minus the output reserve, which is `limit.output` or 32,000 tokens, whichever is smaller. With Qwen3.8 27B's full 1,048,576-token window that is 1,016,576 tokens, where one call costs about $0.20. A `limit.context` of 200,000 compacts at 168,000 tokens and keeps calls near $0.036. Without `limit.context` there is no automatic compaction.
Is Heabsy a built-in provider in OpenCode?+
Not yet. OpenCode's built-in list comes from models.dev, and Heabsy is not listed there; the custom provider block does the same job.