Self-hosted. No data egress. By Nativerse.
AI spend is a black box.
Trust is the meter. TokenLedger puts a number on how much of an AI bill is accountable, and how much is not. Self-hosted, and nothing leaves the box.
Runs alongside a LiteLLM gateway. It audits the numbers and routes nothing. Self-hosted, SQLite on the machine, open source under Apache-2.0.
What it does, step by step.
The result is a bill where every number is either independently confirmed or clearly marked as unverifiable.
Capture the request sent, the response returned, and the token counts the provider claims.
Re-tokenise the actual text with the model's own tokenizer. The provider is never asked to count.
Compare the independent count with the provider's and return a verdict: OK, over-count, or out of band.
Apply pay-per-token or rented-GPU cost models for an effective cost per token that compares like for like.
How sure each figure is
Every figure states what can and cannot be verified.
Output tokens on providers with a public tokenizer. The received text is re-tokenised with tiktoken or the open-weight model's own tokenizer. Billed above counted is a hard discrepancy.
Input tokens and closed models like Claude and Gemini. The sent text is re-counted plus documented overhead, and figures outside a tolerance band are flagged. An estimate is never dollarised as exact.
Reasoning tokens and per-call cache. Billed but never returned, so there is nothing to re-count. Recorded, never asserted.
Every result carries its confidence label. The tool never claims proof it does not have.
Sits beside LiteLLM and audits from the outside.
LiteLLM already writes spend logs. Pointed at them, TokenLedger audits the numbers from the outside. It does not route or proxy any traffic.
# read what the gateway already wrote, re-count it independently retoken ingest litellm_spendlogs.jsonl --format litellm → output re-counted exactly where a tokenizer exists → gateways hand back the provider's own number; re-counted independently as a consistency check, with whatever cannot be checked flagged
A planted over-count, caught and labelled.
The offline demo plants realistic discrepancies and catches them, with every figure carrying its EXACT, BOUNDED, or UNVERIFIABLE label.
| bucket | billed | re-counted | verdict |
|---|---|---|---|
| output | 89 | 64 | over-count, EXACT |
| input | 112 | ~20 | out of band, BOUNDED |
| reasoning | 1,024 | n/a | UNVERIFIABLE |
Offline demo, planted discrepancies. Figures are illustrative, not a measured customer result.
Run it locally in 60 seconds.
pip install "retoken[exact]" retoken demo open retoken_demo.html
No signup, no API keys, nothing leaves the machine.
Questions, answered plainly.
Does my prompt or response data leave my network?
No. All counting and reconciliation run locally. The only network call the system makes is the optional proxy forwarding the original request to the chosen provider. Text can be stored hashed only.
Do I replace my gateway?
No. TokenLedger runs alongside LiteLLM and audits the numbers. It routes nothing.
Can Claude or Gemini token counts be verified exactly?
No, and the tool says so. Closed models are bounded, not exact. Figures outside a tolerance band are flagged, and an estimate is never presented as an exact result.
What about reasoning tokens?
Recorded, never asserted. They are billed but not returned, so there is nothing to re-count.
Is this validated with real customers?
The reconciliation engine, store, dashboard and report are working and tested offline. Demand and the closed-model band width are still being validated with design partners. We will not claim a result we have not measured.
See it run on real logs.
We run a small number of seven-day validations with teams whose AI spend is growing. A team brings a sample of gateway logs and we reconcile them together, with no data leaving the environment.
Prefer to talk first? Use the Book now button, or book a 20-minute call.