Skip to content

Conversation

@Zeng-WH
Copy link

@Zeng-WH Zeng-WH commented Dec 28, 2025

The Python SDK was discarding id and usage fields from assistant messages during parsing, making it impossible to track per-step token usage. This is inconsistent with the TypeScript SDK which preserves these fields.

Changes:

  • Add message_id and usage fields to AssistantMessage dataclass
  • Extract these fields in message_parser.py when parsing assistant messages

Use case:

  • Monitor per-step token consumption for cost analysis
  • Detect when API features like clear_tool_results trigger by observing input_tokens drops between steps
  • Parity with TypeScript SDK behavior

The Python SDK was discarding `id` and `usage` fields from assistant
messages during parsing, making it impossible to track per-step token
usage. This is inconsistent with the TypeScript SDK which preserves
these fields.

Changes:
- Add `message_id` and `usage` fields to `AssistantMessage` dataclass
- Extract these fields in `message_parser.py` when parsing assistant messages

Use case:
- Monitor per-step token consumption for cost analysis
- Detect when API features like `clear_tool_results` trigger by
  observing input_tokens drops between steps
- Parity with TypeScript SDK behavior
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