Optionalopts: ModelAwareEstimatorOptionsEstimates token usage using per-model character ratios.
Accuracy: ±15% for known models on English prose. Falls back to naiveTokenEstimator (ratio 4.0) for unknown models.
v2: respects request.model when present, falling back to defaultModel.
v2: handles multimodal content (text blocks counted, others ignored).
v3.7: counts request.system, adds request.extraInputTokens
verbatim, and applies the opaqueBlockTokens surcharge (when
configured) to every non-text block in messages and system.
Optionaloverrides: Record<string, number>Optionalopts: ModelAwareEstimatorOptions
Estimates token usage using per-model character ratios.
Accuracy: ±15% for known models on English prose. Falls back to naiveTokenEstimator (ratio 4.0) for unknown models.
v2: respects
request.modelwhen present, falling back todefaultModel. v2: handles multimodal content (text blocks counted, others ignored). v3.7: countsrequest.system, addsrequest.extraInputTokensverbatim, and applies theopaqueBlockTokenssurcharge (when configured) to every non-text block in messages and system.