Skip to content

feat(session): add TokenStats for session-level token usage accumulation#125

Open
UncertaintyDeterminesYou4ndMe wants to merge 1 commit intoMoonshotAI:mainfrom
UncertaintyDeterminesYou4ndMe:feat/token-stats
Open

feat(session): add TokenStats for session-level token usage accumulation#125
UncertaintyDeterminesYou4ndMe wants to merge 1 commit intoMoonshotAI:mainfrom
UncertaintyDeterminesYou4ndMe:feat/token-stats

Conversation

@UncertaintyDeterminesYou4ndMe

Add TokenStats dataclass for tracking cumulative token usage per session.

Changes

  • Add TokenStats dataclass with input_other, output, input_cache_read, input_cache_creation fields
  • Add session.token_stats property exposing cumulative statistics
  • Accumulate token usage from StatusUpdate wire messages during prompt() stream
  • Export TokenStats from package init.py

Testing

  • ✅ 8 new tests covering initial zero, accumulation, properties, edge cases
  • ✅ All existing tests pass (33 total)
  • ✅ Lint (ruff) passed
  • ✅ Type check (pyright) passed

Design

The SDK provides data-level token statistics without UI display logic, allowing callers (like kimi-cli) to decide how to present the information.

Related

Part of the token usage stats feature across kimi-cli and kimi-agent-sdk.

- Add TokenStats dataclass to track cumulative token usage per session
- Expose session.token_stats property for callers to access stats
- Accumulate token usage from StatusUpdate wire messages during prompt()
- Add 8 tests covering initial zero, accumulation, properties, and edge cases

The SDK now provides data-level token statistics without handling UI display,
allowing callers to decide how to present the information.
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