Token Counter and Cost Meter
Build an explicit approximate tokenizer, exact recorded-usage accounting, rate-card cost calculation and budget admission. Estimates are labeled and never presented as provider tokenizer counts. Prices are fixture inputs rather than claims about current provider pricing.
Usage reconciliation explaining why real billing differs from preflight estimates.
- Usage reconciliation explaining why real billing differs from preflight estimates.
- Rates are explicit fixture inputs in integer nano-dollars per token, not current provider prices.
Token Counter and Cost Meter in 4 stages
Account for usage and budgets with integer arithmetic.
Estimate text with a documented bound
Count Unicode scalar values and use a configurable characters-per-token ratio with ceiling division.
starter · ~2 hours · Rust
Count scalarsRead ratioCeiling divisionLabel estimateValidate recorded usage
Cached input is a subset of input, never an extra token category to add twice.
core · ~2 hours · Rust
Parse countersCheck unsignedCached subsetUsage recordPrice with checked integers
The fixture rate card uses nano-dollars per token.
core · ~2 hours · Rust
Uncached chargeCache chargeOutput chargeChecked sumAdmit work against a ledger
Reserve a quoted amount only if spent plus quote is within the configured limit.
core · ~2 hours · Rust
Read ledgerChecked additionCompare limitCommit reservation