Repository navigation
fix(opencode): report $0 for free models and expose cost like other engines - #156
Open
namanarora00 wants to merge 2 commits into
Open
namanarora00 wants to merge 2 commits into
namanarora00 wants to merge 2 commits into
Conversation
namanarora00
force-pushed
the
fix/opencode-cost
branch
from
November 2, 2026 14:33
fd8a1b9 to
a69750e
Compare
Contributor
There was a problem hiding this comment.
Review completed against the latest diff
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
…ngines When OpenCode reported a step cost of 0, rae estimated it with calculate_cost, which prices any unknown model as Claude Sonnet 4.6. Free models such as the default opencode/big-pickle and local Ollama models were shown as costing Sonnet prices. Estimate only for models with known prices, and resolve short names (sonnet, opus, haiku) through MODEL_MAP before pricing. OpenCode also kept its cost only under usage.cost, which --json usage, /history and /resume do not read. Record it under estimated_cost_usd as well, and map OpenCode's cache_creation_tokens to cache_write_tokens in --json. The README's agent --json table listed usage.total_cost; the field is total_cost_usd.
namanarora00
force-pushed
the
fix/opencode-cost
branch
from
November 2, 2026 14:36
a69750e to
7c7c029
Compare
Contributor
Comments Outside DiffThese findings could not be posted inline.
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Two problems with how OpenCode runs report cost:
OpenCodeEngineerestimates the cost withcalculate_cost. For any model missing fromMODEL_PRICING,calculate_costfalls back to Claude Sonnet 4.6 prices. So the defaultopencode/big-pickle, which is free, and local Ollama models were shown as costing money: $4.50 per 1M input / 100k output tokens. The same happened to the short names inMODEL_MAP(sonnet,opus,haiku), because they were priced before being mapped.usage.cost.--jsonusage (total_cost_usd),/historyand/resume's session cost all readestimated_cost_usd, which the other engines write. OpenCode's cache writes (cache_creation_tokens) also never reachedcache_write_tokensin--json.What
MODEL_MAP, and estimate a zero API cost only whenget_model_pricingknows the model. Unknown models stay at $0 instead of borrowing Sonnet prices. Known models keep the local estimate added in fix opencode pricing #10 (for example a subscription that reports $0).estimated_cost_usdas well.usage.costis kept, so the OpenCode session summary and existing history are unchanged.cache_creation_tokensto thecache_write_tokenscandidates in_STABLE_USAGE_KEYS.agent --jsontable listedusage.total_cost. The field istotal_cost_usd, next to the cache token counts andraw, asscripted-usage.mdxalready says.test_step_finish_calculates_cost_when_zeronow sets a priced model. With the default freebig-pickle, the correct estimate is $0.Verification
big-pickleand an Ollama model now record $0,opusis priced asclaude-opus-4-6,estimated_cost_usdaccumulates across steps, and_normalize_usagemaps OpenCode's keys.pytest: 1231 passed, 10 skipped, same asmain.ruff check src testsandmypy srcare clean.One behavior to call out: a paid model that is not in
MODEL_PRICING(and not in LiteLLM, when installed), on a provider that reports $0, now shows $0 instead of a Sonnet-priced guess. That seemed more honest than a guess, but say if you'd rather keep a fallback there.This PR and #155 (list/show cost) each add lines in the same CHANGELOG section, so whichever merges second will need a small conflict resolution there.
Summary by cubic
Fixes OpenCode cost reporting so free and local models show $0, and so cost and cache write usage reach the same places other engines report them.
opusthroughMODEL_MAPfirst; unknown models (opencode/big-pickle, Ollama) stay at $0 instead of getting Sonnet 4.6 prices.estimated_cost_usdalongsideusage.cost, so--json,/history, and/resumesee it.cache_creation_tokenstocache_write_tokensin--jsonusage, and notes in the README thatusagefields appear only when the SDK reports them.agent --jsonusage field fromtotal_costtototal_cost_usd.Written for commit 288d4bd. Summary will update on new commits.


Confidence Score: 5/5
The reviewed cost-accounting and usage-export changes are safe to merge; no blocking issues were found.Summary
Fixes OpenCode cost reporting and exposes its cost and cache writes through the existing JSON fields.
namanarora00 explicitly acknowledged that unknown paid models reporting $0 will now show $0, rather than a Sonnet-priced guess. This is intentional to avoid presenting an unknown cost as a known price.
No blocking issues were found in the reviewed changes. The changes are safe to merge within the reviewed scope.
Reviews (1) · Last reviewed commit: "fix(opencode): report $0 for free models..." · Reviewed by Greptile