Estimate Tokens • AI Agent SDK
estimate_tokens: Estimate tokens with optional validation.
estimate_tokens
Method
</div>
This is a method of the ContextManager class in the manager module.
Estimate tokens with optional validation.
Signature
def estimate_tokens(text: str, validate: bool) -> Tuple[int, Optional[EstimationMetrics]]Parameters
ParamField
strText to estimate
ParamField
boolWhether to validate against accurate count
Returns
ResponseField
Tuple[int, Optional[EstimationMetrics]]Tuple of (token_count, metrics)
Uses
estimate_tokens_heuristichexdigesthashlib.sha256text.encodeestimate_tokens_accurateEstimationMetricswarningget_logger
Used By
Source
View on GitHubpraisonaiagents/context/manager.py at line 647