Skip to content

Fix missing usage in SSE stream causing input_tokens crash#39

Merged
Mng-dev-ai merged 1 commit intomainfrom
fix/streaming-usage-and-stop-reason
Feb 17, 2026
Merged

Fix missing usage in SSE stream causing input_tokens crash#39
Mng-dev-ai merged 1 commit intomainfrom
fix/streaming-usage-and-stop-reason

Conversation

@Mng-dev-ai
Copy link
Owner

Summary

  • Emit message_delta with usage on all error paths across openrouter, copilot, and responses_api providers. Previously, error paths skipped the message_delta event, leaving message.usage undefined in the SDK and causing Cannot read properties of undefined (reading 'input_tokens') when Claude Code uses subagents.
  • Emit message_start before error events in the copilot auth error path, which previously sent error → message_stop without initializing the message.
  • Set stop_reason to "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.
  • Bump version to 0.1.35.

Test plan

  • Run Claude Code with subagents through the bridge and verify no input_tokens crash
  • Verify tool-call responses have stop_reason: "tool_use"
  • Trigger an upstream API error and confirm the stream still includes message_delta with usage
  • Run ruff check and mypy (both pass)

- 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
@Mng-dev-ai Mng-dev-ai merged commit d6d687c into main Feb 17, 2026
0 of 2 checks passed
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