llm-spend
Price what your llm history actually cost.
llm already logs every response's token usage to its SQLite database
(logs.db) — input tokens, output tokens, provider token details — but
it never turns those numbers into dollars. This plugin adds one command
that does:
llm install llm-spend-report
llm spend
| Model | Calls | Input tokens | Output tokens | Est. cost |
|---|---:|---:|---:|---:|
| gpt-5 | 2 | 3,000,000 | 500,000 | $7.6250 |
| claude-sonnet-4-5 | 1 | 1,000,000 | 200,000 | $4.6500 |
| local-llama | 1 | 5,000 | 800 | — |
| **Total** | **4** | **4,005,000** | **700,800** | **$12.2750** |
_Total covers priced models only; no price is known for: local-llama (add one with --prices)._
_1 logged call(s) recorded no token usage and are excluded._
Usage
llm spend # all logged calls, grouped by model
llm spend --by day # grouped by day instead
llm spend --days 30 # only the last 30 days
llm spend --model gpt-5 # one model only
llm spend --json # machine-readable report
llm spend --prices my-prices.json # override/extend the price table
llm spend --database /path/to/logs.db # a non-default database
The database is opened read-only — the report never writes to,
migrates, or locks your live logs.db.
How it works
- Both storage eras. Current
llmversions log usage to theturnstable; older versions usedresponses. A call is written to exactly one of them, so both are read and merged. - Cached tokens are priced at the cached rate when the provider's token details record them (OpenAI- and Anthropic-style detail shapes are recognized) and the price table has a cached-input price. Anything unrecognized is priced at the full input rate — never double-discounted.
- Unknown models are never silently $0. A model with no price in the
table is listed with its token counts and a
—cost, and named in the notes. Calls that recorded no token usage at all are counted and excluded. - Model names come from the logged
resolved_modelwhen present, so an alias you called is priced as the model that actually ran.
Prices
The bundled table is example data as of 2026-10-30 (GPT-5 family, GPT-4o family, Claude Sonnet/Haiku 4.5, Gemini 2.5 Pro/Flash) — providers change prices often, so verify before relying on totals, or supply your own file (same shape as below; entries override or extend by name):
{"models": {"my-model": {"input_per_m": 0.40, "output_per_m": 1.60,
"cached_input_per_m": 0.04}}}
Prices are USD per 1M tokens; cached_input_per_m is optional.
Limitations
- Estimates, not invoices. The log records what the provider reported; free tiers, credits, batch discounts, and per-request fees are not in the log and cannot be priced from it.
- Embeddings usage is not priced in this version.
- Alias-only model ids that never resolved to a priced model stay
unpriced until you add them via
--prices.
Development
python -m venv .venv && source .venv/bin/activate
pip install -e ".[test]"
python -m pytest # 11 tests, fully offline
Requires Python ≥ 3.10 and llm itself. Zero additional runtime
dependencies.
License
MIT — see LICENSE. Copyright (c) 2026 Gang Ji.
Not affiliated with the llm project; llm is by Simon Willison.
Metadata
Release files for llm-spend-report 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 |
|---|---|---|---|---|
| llm_spend_report-0.1.0.tar.gz | 9.5 kB | With provenance | Details for llm_spend_report-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| llm_spend_report-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for llm_spend_report-0.1.0-py3-none-any.whl |
Total release size: 17.8 kB
Release files / llm_spend_report-0.1.0.tar.gz
| Download URL | llm_spend_report-0.1.0.tar.gz |
|---|---|
| Size | 9.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f277094112fb6814a28e45f2a3b23f4205027859b605911c2228a7f73525ffd1
|
|
BLAKE2b-256 checksum How to use checksums |
3d255db12b813f8afb7d412c3c63fa1ec067017bfc6f5cbcea28a09fb5fad27f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Oct 30, 2026.
Transparency logRelease files / llm_spend_report-0.1.0-py3-none-any.whl
| Download URL | llm_spend_report-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
37b1f887039405d1840c4451963a34b12570fbf52389dda9c2e49a86b00c6716
|
|
BLAKE2b-256 checksum How to use checksums |
4a3e9b5d80b2eb1599499957c6cc66e2019b5752582d801159fc55de44622849
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Oct 30, 2026.
Transparency logSecurity for llm-spend-report 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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for llm_spend_report-0.1.0.tar.gz
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 Oct 30, 2026.
Transparency logA 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.