Fix model cost units: dollars per million tokens, not per token - #25
Open
CNQQC wants to merge 1 commit into
Open
Fix model cost units: dollars per million tokens, not per token#25CNQQC wants to merge 1 commit into
CNQQC wants to merge 1 commit into
Conversation
opencode and models.dev express `cost.input` / `cost.output` /
`cost.cache_read` / `cost.cache_write` in dollars per MILLION tokens —
opencode divides by 1e6 itself when multiplying a cost by a token count.
models.dev's own entry for the same model reads
`anthropic/claude-haiku-4-5 -> {"input": 1, "output": 5, "cache_read":
0.1, "cache_write": 1.25}`.
The constants here were written as per-token dollars (1e-6 for Haiku
input), so every session cost opencode reported came out exactly
1,000,000x too low — effectively always $0.00. Token counts, including
the cache read/write split, were already correct; only the dollar amount
was wrong.
Verified end-to-end against opencode 1.18.12 with a real Haiku 4.5 turn
(10 input / 62 output / 10,583 cache write / 15,973 cache read):
before: $0.00000002 (reported / actual = 0.000001)
after: $0.01514605 (reported / actual = 1.000000)
The `(N×)` multiplier suffix on display names is unaffected — it is
derived from the input/output price ratios, which are unchanged.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
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.
Problem
src/models.tsdeclares model costs as dollars per token (input: 1e-6for Haiku), but opencode and models.dev expresscost.*as dollars per million tokens — opencode divides by1e6itself when it multiplies a cost by a token count.models.dev's own entry for the same model:
anthropic/claude-haiku-4-5 -> {"input": 1, "output": 5, "cache_read": 0.1, "cache_write": 1.25}Net effect: every session cost opencode reports through this provider is exactly 1,000,000x too low, so the cost indicator sits at
$0.00no matter how much you run. Token counts — including the cache read/write split — were already correct; only the dollar amount was wrong.This is easy to miss because subscription users aren't billed per token anyway. But the figure is still the only in-TUI signal for how fast a session is draining a Max/Pro plan, which is exactly what the
(N×)multiplier in the display name is there to approximate.Fix
Multiply the five cost constants by
1e6so they read as the published per-million-token prices ($1/$5 Haiku, $3/$15 Sonnet, $2/$10 Sonnet 5, $5/$25 Opus, $10/$50 Fable/Mythos). Comment updated to name the unit and cite the models.dev entry so it doesn't regress.The
(N×)multiplier suffix is unaffected — it comes from the input/output price ratios, which don't change.Verification
bun run typecheckclean,bun run buildclean,bun run test— 294/294 pass (the two exactcostassertions intest-config-models.tsupdated to the new unit).End-to-end against opencode 1.18.12, real Haiku 4.5 turn, 10 input / 62 output / 10,583 cache write / 15,973 cache read:
$0.000000020.000001$0.015146051.000000Note on #22 / #23
This touches
sonnet5Cost, which #23 also rewrites for the September 1 standard-pricing bump. Trivial conflict either way — after this lands, that PR's target values become{ input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 }.🤖 Generated with Claude Code