TokenCost (tokencost)
Financial-grade attribution for LLM spend. What did our AI features cost us last month, broken down by feature, team, and customer cohort?
Why
Every CFO is asking "how much are we spending on AI?" and engineering can't answer cleanly. Bills swing 2–3× per quarter unexpectedly. Existing tools (Helicone, Langfuse) touch this but neither is finance-grade.
TokenCost is the system of record:
- Typed schema so downstream finance integrations don't break.
- Money in micro-USD integers so floating-point rounding doesn't accumulate over millions of rows.
- Append-only JSONL store that ships well with any log pipeline.
- Aggregator that produces the four breakdowns finance always wants.
Status
v0.0.1 alpha — data plane only. SDK middlewares (one-line install for OpenAI / Anthropic clients) and the hosted dashboard land in v0.0.2+.
Money model
| Concept | Unit | Why |
|---|---|---|
cost_micros on every row |
micro-USD (integer) | Python float can't represent fractional cents accurately — at 10M rows the drift is real money |
Price table (prices.py) |
micro-USD per million tokens | Mirrors how Anthropic / OpenAI quote rates |
| Markdown reports | dollars (2dp; 4dp for sub-cent) | Human display only; downstream math always uses micros |
CLI
tokencost version
tokencost prices # list the per-model price table baked into this build
# Record one call (manual entry; SDK middleware comes in v0.0.2)
tokencost record \
--provider anthropic \
--model claude-sonnet-4-6 \
--input-tokens 1234 \
--output-tokens 567 \
--feature pr-review \
--environment prod \
--actor customer:acme
# Aggregate one or more JSONL files into a finance report
tokencost report --from-file .tokencost/usage.jsonl
Output: .tokencost/usage.jsonl (append-only event log) + .tokencost/report.{json,md} (aggregated report).
Roadmap
- v0.0.2 —
tokencost.middleware.openaiandtokencost.middleware.anthropic(one-line wrap of the SDK client; auto-records every call). - v0.0.3 — budget alerts:
tokencost check --budget feature:pr-review=$1000/mo. - v0.1 — hosted multi-tenant dashboard at $0.50 per million tracked-tokens.
- v0.1 — finance integrations: NetSuite, Sage, QuickBooks export shape.
- v0.2 — anomaly detection on burn-rate (call out the 2× quarter-over-quarter spike before the CFO asks).
Apache-2.0 license. See CHANGELOG.
Metadata
Release files for devtrust-tokencost 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| devtrust_tokencost-0.0.3.tar.gz | 22.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| devtrust_tokencost-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 42.0 kB
Release files / devtrust_tokencost-0.0.3.tar.gz
| Download URL | devtrust_tokencost-0.0.3.tar.gz |
|---|---|
| Size | 22.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
296cfb0cc96a3bff8da38e93883c10fcd1a10d18607b407b39043ab02923425f
|
|
BLAKE2b-256 checksum How to use checksums |
7f0dbb7802248906f78ced3011ddc704bd63d4eb4c1a47c3d9b1061c7ee1e9b1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 9, 2026.
Transparency logRelease files / devtrust_tokencost-0.0.3-py3-none-any.whl
| Download URL | devtrust_tokencost-0.0.3-py3-none-any.whl |
|---|---|
| Size | 19.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
82a609546c3c98066d4b82633ba5733563f43d3e56966b014c14f9309eed215e
|
|
BLAKE2b-256 checksum How to use checksums |
7ecfbfe6a3356739c07779c4ba98f85a4efcfdfeb19e4ed3e32ff41a71b45a83
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 9, 2026.
Transparency log