How It Works
Quick Start
Estimation Modes
| Mode | Description | Performance |
|---|---|---|
HEURISTIC | Fast character-based estimate | Fastest |
ACCURATE | Use tiktoken if available | Slower |
VALIDATED | Compare both, log mismatches | Slowest |
Configuration
Environment Variables
EstimationMetrics
Mismatch Logging
Whenlog_estimation_mismatch=True and error exceeds threshold:
Estimation Caching
Estimates are cached by content hash:Heuristic Algorithm
The heuristic uses character-based estimation:Accurate Estimation
When tiktoken is available:CLI Usage
Best Practices
Use heuristic mode in production
Use heuristic mode in production
Heuristic estimation is fast and sufficient for most runs — reserve validated mode for debugging.
Set a sensible mismatch threshold
Set a sensible mismatch threshold
Fifteen to twenty percent is a typical threshold before logging estimation drift.
Monitor mismatch logs
Monitor mismatch logs
Spikes often indicate unusual Unicode, code blocks, or tool payloads — fix content, not just the estimator.
Enable tiktoken when available
Enable tiktoken when available
Model-specific tokenisers improve accuracy for billing-sensitive workloads.
Related
Token Estimation
Fast offline token counting
Context Observability
Track optimisation events and history

