Skip to main content

estimate_tokens

Function estimate_tokens 

Source
pub fn estimate_tokens(
    messages: &[Message],
    options: &CountTokensOptions,
) -> u64
Expand description

The default Model::count_tokens estimate: text length / 4 and JSON length / 2, in UTF-16 code units, with only the latest user message’s injected blocks.

Providers with a native counting API fall back to it on failure.