Skip to content

Function: estimateTokens()

ts
function estimateTokens(text): number;

Defined in: packages/core/src/introspection/TokenEconomics.ts:169

Estimate token count from a string using the ~4 chars/token heuristic.

This is a fast approximation suitable for profiling. For precise token counting, use a tokenizer library (tiktoken, etc.).

Parameters

ParameterTypeDescription
textstringThe text to estimate tokens for

Returns

number

Estimated token count