Skip to main content

Module count

Module count 

Source
Expand description

Pure token estimation for LLM requests

Estimation layer built on top of TokenEstimator: counts messages, tools, and multimodal content. Transport-level counting (provider count-tokens API first, estimation as fallback) lives in client::LlmClientImpl::count_tokens_inner; this module never touches HTTP clients or codecs.

Functionsยง

default_estimator
Estimator used by counting helpers.
estimate_image_tokens
Estimate tokens for an image reference.
estimate_message_tokens
Estimate tokens for a single message: content (text / rich blocks), thinking, tool calls, plus a fixed metadata overhead per message.
estimate_messages
Estimate the token count of the current conversation messages.
estimate_request_tokens
Estimate tokens for a full LLM request: messages + tool declarations.
estimate_tool_declarations
Estimate tokens for tool declarations alone (the per-request dynamic overhead that never accumulates into a message-array ledger).