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
For Anthropic and MiniMax models, the task cost reported in the UI omits the output-token portion of the bill. Every task on the default Anthropic provider shows only input + cache-read/write cost — typically 20–40% of the real total.
Mechanism
In src/api/providers/anthropic.ts the streaming loop accumulates outputTokens only from message_start.usage.output_tokens, which Anthropic documents (and the pinned SDK @anthropic-ai/[email protected]MessageStream confirms, lib/MessageStream.js:454 — replace semantics) as a seed value (0 or 1). The real total arrives cumulatively in message_delta.usage.output_tokens, whose final event carries the full count. The message_delta branch yields the value to the consumer but never adopts it into the local accumulator, so the end-of-stream totalCost chunk is computed from the seed.
Task.ts then assigns totalCost = chunk.totalCost (overriding the consumer-side costResult which is summed correctly), so the wrong value wins. Same defect in src/api/providers/minimax.ts. In-repo proof this is a known trap: opencode-go.ts:558-565 fixes exactly this with an explanatory comment.
Repro
Select any Anthropic (or MiniMax) model, run any task.
Open the task cost/token summary.
Compare reported cost against calculateApiCostAnthropic(modelInfo, inputTokens, outputTokens) with the real output count — the output-token term (60–80% of the bill) is missing. Token counts look right because the consumer sums the deltas itself.
Suggested fix
Adopt (not add) the cumulative value in the message_delta case: outputTokens = chunk.usage.output_tokens || outputTokens, mirrored in minimax.ts. Regression tests: stream with message_start usage {input:100, output:1} + message_delta usage {output_tokens:500} → final usage chunk's totalCost must equal cost(info, 100, 500).
Activity