You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
parity: does upstream's client compute cost from tokens and catalog prices? #970
Some providers report a cost of 0 in session, message and usage data, while token counts and the model catalog's prices (ModelInfo.Cost, including cache prices and long-context tiers) are available. Callers that enforce budgets then compute cost themselves from tokens and catalog prices.
Question for parity (ADR-0031): does opencode's first-party client (packages/client, the CLI and TUI) compute or display cost from tokens and catalog prices when the reported cost is 0? If it does, the SDK should offer the same helper. If it doesn't, record that the SDK reports the server's cost as is, and close this.
Done when the upstream behaviour at the pin is cited (file and line), and the SDK either has the matching helper or a recorded "not offered upstream".
Answer from the source at opencode v2.3.2 (c0ad18b4): upstream does not compute cost from tokens when a provider reports 0.
The server computes the catalog cost, with context tiers and cache prices (packages/core/src/session/usage.ts:21-36). It does so only when the provider reports no cost: cost: usage?.cost === undefined ? calculateCost(costs, normalized) : Money.USD.make(usage.cost). The comment on that line says "A reported zero is authoritative" (usage.ts:43-51, and packages/ai/src/schema/events.ts:74-79).
That value reaches the HTTP API on step events, messages, sessions and stats. The CLI, the TUI, ACP and the Solid data store display the server's number unchanged. None of them recomputes it.
The SDK has no hand-written cost helper either, so it matches upstream.
A recomputing helper would be an SDK-only addition, which is a divergence under ADR-0031. One related first-party helper the SDK lacks is filed separately: the family cost sum.
Activity
Blind-Striker commentedon Nov 22, 2026
Answer from the source at opencode v2.3.2 (
c0ad18b4): upstream does not compute cost from tokens when a provider reports 0.packages/core/src/session/usage.ts:21-36). It does so only when the provider reports no cost:cost: usage?.cost === undefined ? calculateCost(costs, normalized) : Money.USD.make(usage.cost). The comment on that line says "A reported zero is authoritative" (usage.ts:43-51, andpackages/ai/src/schema/events.ts:74-79).A recomputing helper would be an SDK-only addition, which is a divergence under ADR-0031. One related first-party helper the SDK lacks is filed separately: the family cost sum.