Estimates token usage using a flat 4-characters-per-token ratio.
Handles both plain string and multimodal content.
Non-text content blocks are ignored (treated as zero tokens).
Accuracy: ±25% for English prose.
Suitable for load-shedding; not suitable for cost accounting.
v3.7: counts request.system alongside message content and adds
request.extraInputTokens verbatim. Non-text blocks still contribute
zero characters (use the model-aware estimator's opaqueBlockTokens
for per-block surcharges).
Estimates token usage using a flat 4-characters-per-token ratio.
Handles both plain string and multimodal content. Non-text content blocks are ignored (treated as zero tokens).
Accuracy: ±25% for English prose. Suitable for load-shedding; not suitable for cost accounting.
v3.7: counts
request.systemalongside message content and addsrequest.extraInputTokensverbatim. Non-text blocks still contribute zero characters (use the model-aware estimator'sopaqueBlockTokensfor per-block surcharges).