Expand description
Token estimation.
Estimates token counts for messages and content blocks using a character-based heuristic. Uses actual API usage data when available, falling back to rough estimation for new messages.
Default ratio: 4 bytes per token (conservative for most content).
Functionsยง
- context_
window_ for_ model - Get the context window size for a model.
- estimate_
block_ tokens - Estimate tokens for a single content block.
- estimate_
context_ tokens - Estimate total context tokens for a message history.
- estimate_
message_ tokens - Estimate tokens for a single message.
- estimate_
tokens - Estimate token count from a string.
- max_
output_ tokens_ for_ model - Get the max output tokens for a model.
- max_
thinking_ tokens_ for_ model - Get the maximum thinking token budget for a model.