tokenaudit
Root-cause diagnosis of wasted LLM tokens — from the traces your agents already emit.
Status: early development, pre-0.1. Interfaces will change.
Every LLM cost tool can tell you how much you spent and who spent it. Almost none can tell you why a specific request wasted money. The biggest lever on an LLM bill — prompt caching, up to a 10× discount on repeated input — fails silently: change one byte of a cached prefix, drop below a model's minimum cacheable size, let a timer expire, and the provider just bills you full price. No error, no warning. There are documented cases of agents running at ~0% cache hit rate for months, at 30–40% unnecessary cost, because of a single line of prompt construction.
tokenaudit reads the traces agents already produce and, for each expensive request, answers four questions: what was wasted, why, what it cost, and what to change.
Quickstart
pip install tokenaudit
tokenaudit diagnose --sample # diagnose the bundled demo trace
tokenaudit diagnose mytraces/ --html report.html
Zero runtime dependencies; reads OTLP/JSON files and OTel SDK JSONL. Try it
on this repo's real captured runs: tokenaudit diagnose corpus/captured/runs.
The plan, in one line each:
- Ingest standard traces — OpenTelemetry GenAI in all three of its cache-field naming generations, OpenInference, raw provider SDK logs — into one normalized accounting model.
- Run a library of deterministic detectors for the silent failure modes: prefix drift, sub-minimum cache blocks, model switches, TTL expiry, breakpoint and lookback limits, tool-schema churn and bloat, context bloat, retry storms.
- Price each finding against a counterfactual — what the bill would have been under the fix — as a bounded range, never a point guess.
- Publish per-detector precision and recall against a labeled corpus, so you know how much to trust each finding.
Prior art
This space is crowded, and being precise about what already exists is the point of this section.
| Tool | What it does |
|---|---|
| CacheLens | Closest prior art. Dev-time SDK wrapper that meters cache hit rate and prefix stability per prompt layer in apps you instrument. Doesn't read existing traces, and prefix stability is its one diagnosis. |
| Helicone | Observability proxy: cost and token accounting per user/session/feature, including cache token counts |
| Langfuse | Open-source LLM engineering platform: tracing, evals, per-trace cost accounting |
| Datadog LLM Observability | Enterprise monitoring: per-request token and cost tracking, quality-issue clustering |
| Braintrust | Evals and observability; its Loop assistant root-causes quality failures |
| LiteLLM | Gateway with budgets, rate limits and spend tracking across providers |
| ccusage | CLI usage and cost reporting from Claude Code's local logs |
| Cloudflare AI Gateway | Platform-level caching, spend caps and alerts |
All of these answer "how much", and several now count cache tokens. The ones that do automatic root-cause analysis target response quality, not cost. The closest tool diagnoses one failure mode, for one integration style, going forward only. What none of them do is take the telemetry any agent already emitted — no code changes, any vendor — and say: these 44 requests missed cache because the system prompt embeds a timestamp; here is the evidence, and here is what it cost. That attribution step is this project.
If you know a tool that already does this, please open an issue — I would genuinely rather find out now.
What tokenaudit is not
- Not a dashboard. The tools above already report spend well.
- Not a proxy, gateway, or wrapper. It reads traces after the fact and never sits in the request path, so it can't change what it measures and doesn't need your code.
- Not an LLM reading your logs. Verdicts come from explicit rules with unit tests and a published false-positive rate (decision 001).
- Not a savings guarantee. Estimates are ranges with stated assumptions, and requests whose telemetry fails a plausibility check are flagged as unpriceable, not silently priced.
Planned layout
src/tokenaudit/
ingest/ trace readers + schema normalization
model/ normalized requests/sessions + token accounting
detect/ the diagnosis engine (deterministic detectors)
counterfactual/ what the bill would have been under a fix
report/ CLI, JSON and HTML output
ci/ cost-regression gate for pipelines
Roadmap
- Prior-art survey, positioning, project scaffold
- Labeled trace corpus: synthetic known-answer fixtures + captured runs from real public agents
- Trace reader and normalizer with a data-quality gate (bad telemetry is refused, not zero-filled)
- Provider caching rulebook: minimums, TTL semantics, invalidation rules — versioned, with sources
- Detectors, starting with prefix drift, sub-minimum blocks, and model/version switch
- Evaluation harness: per-detector results published in eval/results.md
-
tokenaudit diagnoseCLI, HTML report, cache health score - CI cost-regression mode: fail a build that tanks the cache hit rate
- Case studies on public agents, with reproduction commands
Development
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
pre-commit install
pytest
License
Apache-2.0
Metadata
Release files for tokenaudit 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tokenaudit-0.1.0.tar.gz | 2.8 MB | Without provenance | Details for tokenaudit-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tokenaudit-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for tokenaudit-0.1.0-py3-none-any.whl |
Total release size: 2.9 MB
Release files / tokenaudit-0.1.0.tar.gz
| Download URL | tokenaudit-0.1.0.tar.gz |
|---|---|
| Size | 2.8 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
36d82cf40b5994cad8140fd46dde1fed7984e94628b9f6c163fd7861d85a900c
|
|
BLAKE2b-256 checksum How to use checksums |
d94e39827e3e7392f0408000581c8aab2ef81df8477d4dd2334052a99e9b574c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.14
|
Release files / tokenaudit-0.1.0-py3-none-any.whl
| Download URL | tokenaudit-0.1.0-py3-none-any.whl |
|---|---|
| Size | 60.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6cb42ecd86a1dd3e6cda5d01018bfcafc706a2a2b15bdbc0b545f9ae5ab9d408
|
|
BLAKE2b-256 checksum How to use checksums |
b1015a0b26bfa0ba07e23a3b4b93f645a5d908dbcd0e19f41f3b56c84be0f02e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.14
|
Security for tokenaudit 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.