Skip to main content

Module tokens

Module tokens 

Source
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.