Financial-grade attribution for LLM spend: per-feature, per-team, per-customer.
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file devtrust_tokencost-0.0.3.tar.gz.
File metadata
- Download URL: devtrust_tokencost-0.0.3.tar.gz
- Upload date:
- Size: 22.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
296cfb0cc96a3bff8da38e93883c10fcd1a10d18607b407b39043ab02923425f
|
|
| MD5 |
2a82fde31d654e0b82be363090616995
|
|
| BLAKE2b-256 |
7f0dbb7802248906f78ced3011ddc704bd63d4eb4c1a47c3d9b1061c7ee1e9b1
|
Provenance
The following attestation bundles were made for devtrust_tokencost-0.0.3.tar.gz:
Publisher:
release.yml on AbdullahBakir97/DevTrust
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
devtrust_tokencost-0.0.3.tar.gz -
Subject digest:
296cfb0cc96a3bff8da38e93883c10fcd1a10d18607b407b39043ab02923425f - Sigstore transparency entry: 1486586313
- Sigstore integration time:
-
Permalink:
AbdullahBakir97/DevTrust@c6fc601fa074dc0135f1b9a7b5e46360ec1d9d4e -
Branch / Tag:
refs/tags/devtrust-tokencost-v0.0.3 - Owner: https://github.com/AbdullahBakir97
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c6fc601fa074dc0135f1b9a7b5e46360ec1d9d4e -
Trigger Event:
push
-
Statement type:
File details
Details for the file devtrust_tokencost-0.0.3-py3-none-any.whl.
File metadata
- Download URL: devtrust_tokencost-0.0.3-py3-none-any.whl
- Upload date:
- Size: 19.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82a609546c3c98066d4b82633ba5733563f43d3e56966b014c14f9309eed215e
|
|
| MD5 |
329b7d0e7a36a27d5d6c114c3fa064d5
|
|
| BLAKE2b-256 |
7ecfbfe6a3356739c07779c4ba98f85a4efcfdfeb19e4ed3e32ff41a71b45a83
|
Provenance
The following attestation bundles were made for devtrust_tokencost-0.0.3-py3-none-any.whl:
Publisher:
release.yml on AbdullahBakir97/DevTrust
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
devtrust_tokencost-0.0.3-py3-none-any.whl -
Subject digest:
82a609546c3c98066d4b82633ba5733563f43d3e56966b014c14f9309eed215e - Sigstore transparency entry: 1486586417
- Sigstore integration time:
-
Permalink:
AbdullahBakir97/DevTrust@c6fc601fa074dc0135f1b9a7b5e46360ec1d9d4e -
Branch / Tag:
refs/tags/devtrust-tokencost-v0.0.3 - Owner: https://github.com/AbdullahBakir97
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c6fc601fa074dc0135f1b9a7b5e46360ec1d9d4e -
Trigger Event:
push
-
Statement type: