Expand description
Token estimation and usage tracking for agent sessions.
This module provides approximate token counting for messages and cumulative usage tracking across turns. Token estimation uses character-based heuristics:
- ASCII text: ~4 characters per token
- Non-ASCII text (CJK, etc.): ~2 characters per token
The request admission layer adds an explicit safety margin for text. Image parts use a conservative declared-size policy because dimensions are not always available at this boundary.
Structsยง
- Model
Pricing - Pricing information for a language model, expressed as cost per 1,000 tokens.
- Token
Estimator - Estimates token counts for messages and tracks cumulative usage across turns.