Skip to content

fix(opencode): bill session-level reasoning tokens at the output rate - #1342

Open
ozymandiashh wants to merge 2 commits into
getagentseal:mainfrom
ozymandiashh:fix/1334-opencode-usage-mismatch
Open

fix(opencode): bill session-level reasoning tokens at the output rate#1342
ozymandiashh wants to merge 2 commits into
getagentseal:mainfrom
ozymandiashh:fix/1334-opencode-usage-mismatch

Conversation

@ozymandiashh

Copy link
Copy Markdown
Collaborator

While looking into #1334 I found that the SQLite session-level fallback in the OpenCode parser priced tokens_output and dropped tokens_reasoning, while still reporting the reasoning tokens. OpenCode bills reasoning at the output rate, and our per-message path already did, so a session that fell back to the session row showed thinking tokens but never charged for them.

Both the fallback and buildAssistantCall now go through billableOutputTokens, the same rule the cache-rehydration path uses. For the per-message path that's behaviour-neutral; it just removes the duplicate sum that let the fallback drift. Displayed token totals don't change.

Tests: a failing fixture test for the session-level fallback, plus regression locks for per-message reasoning pricing in both the SQLite and JSON parsers. With the fix reverted the new fallback test fails ($0.04965 vs $0.10965); with it in place the OpenCode, OpenCode-file, Kilo and models suites pass and tsc is clean.

This does not close #1334. That report has matching tokens and a different cost, which comes down to per-token rates rather than reasoning. I've asked for a per-model breakdown there.

Refs #1334

When none of a session's messages produce a priced call, the SQLite
parser falls back to the totals on OpenCode's session row. That path
passed tokens_output alone to calculateCost and dropped
tokens_reasoning, while still reporting reasoningTokens, so thinking
tokens were shown but never charged. OpenCode bills reasoning at the
output rate and the per-message path already did the same.

Route both the fallback and buildAssistantCall through
billableOutputTokens so they share one rule with the cache-rehydration
path. The per-message change is behaviour-neutral for opencode and
kilo-code; it only removes the hand-rolled sum that let the fallback
drift.

Refs getagentseal#1334
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.

Usage does not match OpenCode dashboard

1 participant