Skip to main content

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.2tokencost.middleware.openai and tokencost.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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

devtrust_tokencost-0.0.3.tar.gz (22.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

devtrust_tokencost-0.0.3-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

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

Hashes for devtrust_tokencost-0.0.3.tar.gz
Algorithm Hash digest
SHA256 296cfb0cc96a3bff8da38e93883c10fcd1a10d18607b407b39043ab02923425f
MD5 2a82fde31d654e0b82be363090616995
BLAKE2b-256 7f0dbb7802248906f78ced3011ddc704bd63d4eb4c1a47c3d9b1061c7ee1e9b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for devtrust_tokencost-0.0.3.tar.gz:

Publisher: release.yml on AbdullahBakir97/DevTrust

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file devtrust_tokencost-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for devtrust_tokencost-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 82a609546c3c98066d4b82633ba5733563f43d3e56966b014c14f9309eed215e
MD5 329b7d0e7a36a27d5d6c114c3fa064d5
BLAKE2b-256 7ecfbfe6a3356739c07779c4ba98f85a4efcfdfeb19e4ed3e32ff41a71b45a83

See more details on using hashes here.

Provenance

The following attestation bundles were made for devtrust_tokencost-0.0.3-py3-none-any.whl:

Publisher: release.yml on AbdullahBakir97/DevTrust

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page