Run Claude Code on Open Models for About a Cent a Step
Updated: · Published:
Claude Code works with any Anthropic-compatible endpoint, so you can run it on Qwen3.8 27B by setting ANTHROPIC_BASE_URL and pinning its three model aliases. At our catalog prices on 31 October 2026, an average agent step — 52,000 tokens of context, 90% of it served from the prompt cache, 330 tokens out — costs $0.0102. On a real GitHub issue it reached the same fix as an open pull request in 55 steps, for $0.39. Expect dependable routine coding, not Claude's judgement on large, ambiguous changes.
Claude Code is a terminal agent: it reads your repository, runs commands and edits files in a loop, and every turn of that loop is one request to the model. Nothing in the client is tied to Anthropic’s servers — the base URL, the key and the model names are all environment variables. Point them at an endpoint that speaks the Anthropic Messages API and the same agent runs on an open-weight model.
This article sets that up on Qwen3.8 27B, works out what a step costs at our catalog prices, checks the number on a real GitHub issue, explains why the prompt cache matters more than the price per token, and is specific about where the model falls short of Claude.
How do you point Claude Code at an open model?
Seven variables. The base URL has no /v1 suffix — Claude Code appends /v1/messages itself.
export ANTHROPIC_BASE_URL=https://api.heabsy.com # no /v1
export ANTHROPIC_AUTH_TOKEN="$HEABSY_API_KEY"
export ANTHROPIC_MODEL=qwen38
export ANTHROPIC_DEFAULT_OPUS_MODEL=qwen38
export ANTHROPIC_DEFAULT_SONNET_MODEL=qwen38
export ANTHROPIC_DEFAULT_HAIKU_MODEL=qwen38-fable # titles, summaries, background work
export CLAUDE_CODE_MAX_CONTEXT_TOKENS=1048576 # qwen38's real window
claude
What each one does:
ANTHROPIC_AUTH_TOKENgoes out asAuthorization: Bearer …. IfANTHROPIC_API_KEYis also set in your shell, unset it, or Claude Code sends that one instead.- The three
ANTHROPIC_DEFAULT_*_MODELvariables pin the built-in aliases. Without them, Plan Mode,/model sonnetand subagents ask for an Anthropic model ID and get a 404. - The Haiku alias runs background work — session titles, summaries.
qwen38-fablecosts $0.10 per million input tokens, so that traffic does not bill at the main model’s price. - For a model ID it does not recognise, Claude Code assumes a 200,000-token window and compacts early. Qwen3.8 27B has 1,048,576 tokens; telling Claude Code so means fewer compactions, and each compaction costs you the cache (more on that below).
To keep it, put the same values in the env block of ~/.claude/settings.json — your user settings, not a project file that gets committed with the key. Windows commands, the VS Code extension and a list of error messages with fixes are in the Claude Code setup guide.
Check it worked: inside Claude Code, /status should show https://api.heabsy.com as the base URL. Then ask it to list the files in the current folder — that one request exercises tool calling end to end.
What does one agent step cost?
A step is one request: the whole conversation so far — system prompt, tool definitions, the files it has read, the command output it has seen — plus the model’s reply. The context grows as the task goes on, and the agent resends all of it every time.
Our gateway logs give an average step for coding agents: 52,000 tokens of context, of which 90% is a prefix the previous step already sent, and about 330 tokens of output. Priced at the catalog on 31 October 2026:
| Model | Input / cached input / output, per 1M tokens | One step | 100 steps |
|---|---|---|---|
qwen38 — Qwen3.8 27B |
$1.05 / $0.08 / $3.15 | $0.0102 | $1.02 |
mimo-v26-flash — MiMo V2.6 Flash |
$0.50 / $0.20 / $1.50 | $0.0125 | $1.25 |
Anthropic’s own models cost more per step at the same profile; their current prices are on Anthropic’s pricing page.
The arithmetic for Qwen3.8 27B, so you can redo it with your own numbers:
46,800 cached tokens × $0.08 / 1M = $0.00374
5,200 new tokens × $1.05 / 1M = $0.00546
330 output tokens × $3.15 / 1M = $0.00104
--------
$0.0102 per step
How many steps a task takes depends on the task, not on the model’s price: a one-line fix may take a handful, a feature with tests can take a hundred. The model catalog has the current prices; they change, and the table above is dated for that reason. How the step price moves with context size and cache rate, and when MiMo V2.6 Flash is the cheaper of the two, is worked out in What an agent step costs.
What did a real task cost?
To check the calculation, we ran Claude Code non-interactively (claude -p) through api.heabsy.com on a real issue: python-tabulate #460, where BEL-terminated OSC 8 hyperlinks inflate column widths. The prompt asked to fix the bug in the library, add a regression test and run the test suite. Same prompt and checkout for both models, one run each, 31 October 2026:
qwen38 — Qwen3.8 27B |
mimo-v26-flash — MiMo V2.6 Flash |
|
|---|---|---|
| Result | same change as PR #475, regression test added; 324 passed, 60 skipped | same change as PR #475 plus a fix in the bytes branch, regression test added; 326 passed, 60 skipped |
| Steps (requests to the model) | 55 | 43 |
| Cost of the whole task | $0.39 | $0.37 |
| Cost per step | $0.0071 | $0.0086 |
| Median time to first token | 0.28 s | 0.35 s |
| Wall-clock time | 4 min 42 s | 2 min 48 s |
The 60 skipped tests were skipped before the change as well. Two public pull requests already address this issue — #475 with the same one-line change and a test, and #462, a broader one — and both models arrived at the same change as #475: accept BEL as an OSC terminator. The issue was opened on 2 October 2026 and its fixes are public, so a model may have seen similar code in training. Treat the run as an example of what an agent step costs, not as proof that a model is smarter.
What the run adds to the calculation above:
- The measured step was cheaper than the profile: on the Qwen3.8 27B run, 97% of input tokens came from the prompt cache, against 90% in the profile. The calculation is the method; the run is one confirmation of it, on one task.
- MiMo V2.6 Flash cost more per step but less per task. Its cached input costs $0.20 per million against $0.08, and with 97% of input cached, that price decides the step. It needed 12 fewer steps and finished in a bit more than half the time.
- The first request is the slow one. Claude Code’s system prompt is about 12,700 tokens, and on a cold start none of it is in the cache yet. From the second step on, that prefix is cached.
- Both agents worked around a denied command.
rmwas not on the allowed list; to delete a temporary test file, each model wroteos.remove(__file__)into a test and ran it. A permission list on shell commands is not a boundary: run coding agents in a container or a disposable checkout.
Get an API key: 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.
Why does the prompt cache matter more than the price per token?
Look at the arithmetic again: the 46,800 tokens the agent resends cost less than the 5,200 new ones, because they are billed at the cached price. Without the cache, the same Qwen3.8 27B step costs $0.0556 — 5.4 times as much. For an agent, the cached price is the one that decides the bill.
On our API the cache works without any setting: when a request starts with the same tokens as an earlier one on the same model, that prefix is not recomputed and is billed at the cached price. In agent sessions on our gateway, 79–92% of input tokens come from the cache.
Three things break the prefix and make the next step pay full price:
- Compaction.
/compact, or an automatic compaction, rewrites the history into a summary, so the next request starts differently. This is why the real context window inCLAUDE_CODE_MAX_CONTEXT_TOKENSmatters. - Switching models. The cache belongs to a model. After
/model, the first step on the new model pays for the whole context. - Changing the system prompt or tools mid-session, for example adding an MCP server. Everything after the change is new to the cache.
What should you expect from Qwen3.8 27B?
Qwen publishes these results for Qwen3.8 27B: 61.7 on SWE-bench Pro, 73.0 on Terminal Bench 2.1, 90.3 on LiveCodeBench v6 (model card). We have not re-run them, and a benchmark score is not your codebase.
What that means for daily use, stated plainly:
- Hand it: edits in code it can read, writing and fixing tests, refactors with a clear target, explaining a module, shell work, small features with a spec.
- Expect more steering on: changes that span many files and need a design decision first, unfamiliar frameworks, and long unattended runs — give it a narrower task and check in more often.
- It does not replace Claude for the hardest part of the work. Run the routine steps on Qwen3.8 27B and keep Claude for the work that needs it.
Qwen3.8 27B reads images, so a screenshot of an error or a UI works as input. The model page lists the sampling settings Qwen recommends for thinking and direct mode.
When should you switch models in the middle of a task?
One switch is worth having ready, on the same key: mimo-v26-flash for input that is mostly new. Its fresh input costs $0.50 per million against $1.05, so it is the cheaper of the two when less than about 84% of the input comes from the prompt cache (What an agent step costs); at the profile above it costs $0.0125 per step. Start Claude Code with claude --model mimo-v26-flash and set CLAUDE_CODE_MAX_CONTEXT_TOKENS=1048576.
The /model picker lists only IDs that contain claude or anthropic, so qwen38 and mimo-v26-flash do not appear there; start the session with --model, or add one entry with ANTHROPIC_CUSTOM_MODEL_OPTION. Remember the cache: a switch costs one full-price step.
Where does your code go?
Qwen3.8 27B, Qwen3.8 27B Fable and MiMo V2.6 Flash run on GPUs we operate in the European Economic Area; prompts and completions are processed in memory and not stored. We keep billing data — model, token counts, time — not the text. Partner-hosted models in the catalog follow their provider’s policy, without zero data retention and without an EEA guarantee; each is marked in the catalog. Invoices come from an EU company.
When is this setup a poor fit?
- You need Claude-level results on large, ambiguous refactors and cannot afford to steer. Use Claude for that work.
- You rely on Remote Control or voice input: Claude Code switches both off when
ANTHROPIC_BASE_URLpoints elsewhere. - You need vendor support for the combination. Anthropic does not support Claude Code with non-Claude models through gateways, and Heabsy is not affiliated with Anthropic.
- Every model you use on the key must stay in the EEA: our own models above do, partner-hosted models in the catalog do not guarantee it.
Claude Code and Claude are trademarks of Anthropic.