Skip to content

fix(streaming): initialize usage when message_start omits it - #1

Open
dajiaohuang wants to merge 1 commit into
mainfrom
fix/streaming-usage-initialization
Open

dajiaohuang wants to merge 1 commit into
mainfrom
fix/streaming-usage-initialization

Conversation

@dajiaohuang

@dajiaohuang dajiaohuang commented Sep 2, 2026 •

Copy link
Copy Markdown
Owner

The usage initialization problem already has an active upstream submission at anthropics#1815. That proposal includes stable/beta and sync/async regressions and preserves unknown token counts; this older fork patch has no added regression tests. Retained as a historical reference; no duplicate upstream submission is planned.

When message_start event omits the usage field, the usage is never
initialized. This causes errors later when message_delta tries to
access current_snapshot.usage.output_tokens.

This fix ensures usage is initialized with default values (input_tokens=0,
output_tokens=0) when message_start omits it.
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