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
Anthropic streaming spans keep message_start input/cache token counts instead of the final message_delta usage #25621
Stream an Anthropic message whose message_delta.usage reports larger cumulative input_tokens / cache_creation_input_tokens / cache_read_input_tokens than message_start (server tools such as web search do this; a mocked stream with message_start input 50 / cache 10 / 20 and a final message_delta with input 120 / cache 30 / 70 shows it too).
Look at the gen_ai.usage.input_tokens and cache attributes of the resulting span.
Expected Result
The span reports the final cumulative counts from message_delta (120 / 30 / 70 in the mocked stream), since Anthropic's message_delta usage is the running total.
Actual Result
The span keeps the message_start values (50 / 10 / 20). handleMessageMetadata in packages/server-utils/src/ai/anthropic-ai/streaming.ts reads only output_tokens from message_delta.
Additional Context
Proposed fix: when message_delta.usage carries numeric input_tokens / cache_* values, overwrite the message_start values with them (they are totals, not increments) and recompute the prompt total; keep the message_start values when the delta omits them. A patch with tests is ready; happy to open the PR.
Activity
linear-code commentedon Oct 21, 2026
JS-3985
andreiborza commentedon Oct 22, 2026
Hi @pcbeingused333, thanks for filing this one too :). We'll look into it.
fix(server-utils): Use cumulative input and cache token counts from s…
github-actions commentedon Oct 28, 2026
A PR closing this issue has just been released 🚀
This issue was referenced by PR #25623, which was included in the 11.10.0 release.