Skip to content

Fix model cost units: dollars per million tokens, not per token - #25

Open
CNQQC wants to merge 1 commit into
khalilgharbaoui:masterfrom
CNQQC:fix/cost-units-per-million-tokens
Open

Fix model cost units: dollars per million tokens, not per token#25
CNQQC wants to merge 1 commit into
khalilgharbaoui:masterfrom
CNQQC:fix/cost-units-per-million-tokens

Conversation

@CNQQC

@CNQQC CNQQC commented Aug 4, 2026

Copy link
Copy Markdown

Problem

src/models.ts declares model costs as dollars per token (input: 1e-6 for Haiku), but opencode and models.dev express cost.* as dollars per million tokens — opencode divides by 1e6 itself 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.00 no 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 1e6 so 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 typecheck clean, bun run build clean, bun run test — 294/294 pass (the two exact cost assertions in test-config-models.ts updated 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:

reported cost reported ÷ actual
before $0.00000002 0.000001
after $0.01514605 1.000000

Note 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

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>
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant