Skip to main content
Token estimation validation compares heuristic estimates against accurate counts, logging mismatches for debugging. The user monitors context size; validated estimation compares heuristics to accurate counts and logs mismatches.

How It Works

Quick Start

1

Enable validated estimation

2

Review mismatch logs

Estimation Modes

Configuration

Environment Variables

EstimationMetrics

Mismatch Logging

When log_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

Heuristic estimation is fast and sufficient for most runs — reserve validated mode for debugging.
Fifteen to twenty percent is a typical threshold before logging estimation drift.
Spikes often indicate unusual Unicode, code blocks, or tool payloads — fix content, not just the estimator.
Model-specific tokenisers improve accuracy for billing-sensitive workloads.

Token Estimation

Fast offline token counting

Context Observability

Track optimisation events and history