Fix missing usage in SSE stream causing input_tokens crash#39
Merged
Mng-dev-ai merged 1 commit intomainfrom Feb 17, 2026
Merged
Fix missing usage in SSE stream causing input_tokens crash#39Mng-dev-ai merged 1 commit intomainfrom
Mng-dev-ai merged 1 commit intomainfrom
Conversation
- Emit message_delta with usage on all error paths (openrouter, copilot, responses_api) so the SDK always receives a valid usage object - Emit message_start before error events in copilot auth error path - Set stop_reason to "tool_use" when tool calls are present instead of always using "end_turn" - Bump version to 0.1.35
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
message_deltawith usage on all error paths across openrouter, copilot, and responses_api providers. Previously, error paths skipped themessage_deltaevent, leavingmessage.usageundefined in the SDK and causingCannot read properties of undefined (reading 'input_tokens')when Claude Code uses subagents.message_startbefore error events in the copilot auth error path, which previously senterror → message_stopwithout initializing the message.stop_reasonto"tool_use"when the response contains tool calls, instead of always hardcoding"end_turn". Subagents use tools heavily, so every tool-call response was mislabeled.Test plan
input_tokenscrashstop_reason: "tool_use"message_deltawith usageruff checkandmypy(both pass)