llmcostledger
A cost ledger for large language model usage: deterministic pricing, VRAM budgeting, self-host break-even, a dual-source price feed, a static site with a JSON API, and a dataset export.
The package has no runtime dependencies. Everything runs on the Python 3.11
standard library, and a curated snapshot ships inside the wheel, so a fresh
pip install answers questions with no network access.
What is in the box
| Part | Module | What it does |
|---|---|---|
| Canonical encoding | llmcostledger.canonical |
Sorted-key JSON bytes, stable SHA-256, refuses NaN/Infinity |
| Bounded IO | llmcostledger.io_guard |
Byte-capped HTTP fetches, atomic file writes, bounded reads |
| Normalizer | llmcostledger.normalizer |
Version-tolerant parsing of provider records |
| Pricing | llmcostledger.pricing |
Cache-hit share, retries, blended effective cost |
| VRAM | llmcostledger.vram |
Weights, KV cache and total VRAM per quantization |
| Break-even | llmcostledger.breakeven |
GPU rental versus API cost at a token volume |
| Sources | llmcostledger.sources |
OpenRouter + LiteLLM merge with LiteLLM precedence |
| Diff engine | llmcostledger.diff_engine |
Price drops and hikes, context changes, deprecations |
| Quarantine | llmcostledger.quarantine |
Blocks >35% price drops and >10x price jumps |
| Drift bridge | llmcostledger.drift_bridge |
Pulls a public drift feed through the bounded HTTP guard |
| Site builder | llmcostledger.site_builder |
Static HTML, JSON API, RSS, sitemap, SVG badges |
| CLI | llmcostledger.cli |
calc, vram, breakeven, list, diff, build-site, verify |
| SDK | llmcostledger.sdk |
Seed loading, reports, verification, bounded live sync |
| Dataset export | llmcostledger.hf_export |
JSONL always, Parquet when pyarrow is installed |
Install
python -m pip install . # from a checkout
python -m pip install "llmcostledger[hf]" # adds pyarrow for Parquet export
Python 3.11 or newer. dependencies = [] in pyproject.toml;
pyarrow and pytest are optional extras, never required at runtime.
Command line
llmcostledger calc --model openai/gpt-4o --input-tokens 8000 --output-tokens 500
llmcostledger calc --model openai/gpt-4o --cache-hit-rate 0.6 --retry-rate 0.05
llmcostledger vram --model meta/llama-3.3-70b-instruct --quantization int4 --context 8192
llmcostledger breakeven --model meta/llama-3.3-70b-instruct --daily-tokens 100000000 --gpu rtx-4090 --quant fp16 --context 8192
llmcostledger list --json
llmcostledger diff --previous old_snapshot.json --current new_snapshot.json
llmcostledger build-site --snapshot data/latest_snapshot.json --output _site
llmcostledger verify --snapshot data/latest_snapshot.json
Every command except diff accepts --snapshot path.json to read a specific
snapshot instead of the bundled seed; diff takes --previous and --current
snapshot files instead. Typed failures exit 1 with a message on stderr; usage
errors exit 2.
breakeven prices the smallest whole GPU count that holds the model at the
requested --quant and --context, exactly like the site calculator. A model
with no published architecture profile (for example openai/gpt-4o) has no
self-hosting side to price: the command reports it as API-only rather than
inventing a one-GPU cost.
Python SDK
from datetime import UTC, datetime
from llmcostledger import sdk
snapshot = sdk.load_seed_snapshot() # no network, no files needed
spec = sdk.find_model(snapshot, "gpt-4o") # canonical slug, alias or display name
report = sdk.cost_report(spec, input_tokens=8000, output_tokens=500, cache_hit_rate=0.6)
print(report["request_cost_usd"])
live = sdk.sync_latest(now=datetime.now(UTC)) # bounded GET + versioned disk cache
sync_latest reads https://llmcostledger.github.io/api/v1/latest.json with a
byte cap, a timeout and an empty header set, and caches the parsed snapshot on
disk so a repeated call works offline.
Static site and JSON API
llmcostledger build-site --output _site writes:
index.html,models/<slug>.html,calculator/index.html,changelog/index.html,drift/index.htmlapi/v1/latest.json,api/v1/changelog.jsonandapi/models.jsonfeed.xml,rss.xml,sitemap.xml,robots.txtassets/site.css, and three SVG badges per model underbadges/: price per 1M tokens, context window, last sync date
The calculator page is a static simulator: calculator/index.html?model=<slug>
computes cost, VRAM, KV cache and self-host break-even in the browser from the
snapshot embedded in the page. The site is rebuilt from the committed snapshot on
every deploy, so the published JSON API and the pages never disagree.
Per-model JSON lives at api/v1/models/<file_slug>.json, where <file_slug>
is the sanitized file segment for the model, not the raw canonical slug:
the live catalog's GPT-4o record gpt-4o is served from
api/v1/models/gpt-4o.json, and the seed catalog's openai/gpt-4o from
api/v1/models/openai-gpt-4o.json. The
endpoints.model_template value in latest.json uses the same {file_slug}
placeholder, and each record in latest.json carries its exact urls.json
path, so consumers never need to guess the mapping.
Dataset export
python -m llmcostledger.hf_export --snapshot data/latest_snapshot.json --output hf_dataset
python -m llmcostledger.hf_export --output hf_dataset --no-parquet --json
The export writes snapshot.jsonl (one canonical JSON object per line), a
README.md dataset card and dataset_manifest.json. When pyarrow is
importable it also writes snapshot.parquet with an explicit Arrow schema
(floats as float64, token counts as int64, everything else string) and the
manifest records "formats": ["jsonl", "parquet"]. Without pyarrow the JSONL
column set is the export, and the manifest records why Parquet was not produced.
GitHub Actions
Four workflows live in .github/workflows/. None of them needs a personal
access token, a PyPI password or a stored registry credential.
| Workflow | Trigger | What it does | Permissions |
|---|---|---|---|
deploy_pages.yml |
push to main, manual, workflow_call |
Verifies the snapshot, builds _site, deploys with actions/deploy-pages@v4 |
contents: read, pages: write, id-token: write |
daily_sync.yml |
cron 17 6 * * *, manual with force_override |
Fetches both feeds, quarantines anomalies, diffs, verifies, commits the accepted snapshot, dispatches the deploy | contents: write, actions: write, issues: write |
publish_pypi.yml |
release published, manual | Runs the suite, builds sdist and wheel, publishes with OIDC trusted publishing | contents: read (build), id-token: write (publish) |
sync_hf.yml |
cron 43 7 * * 1, manual |
Exports the dataset, uploads it when HF_TOKEN is set; non-blocking |
contents: read |
Daily sync and the quarantine
The sync job reads the two public price feeds with a 16 MB byte cap and a 30 s
timeout each, merges them through the alias resolver (LiteLLM wins on a
conflict), and runs the anomaly quarantine. The quarantine blocks a snapshot when
the model count drops by more than 35%, when the median input price across the
models present in both snapshots increases by a factor of more than 10, or when any
matched model's input price drops by more than 35%, unless the manual run sets
force_override.
The workflow is the only clock adapter: it stamps as_of_date and snapshot_id
from date -u and passes them in, so the library never reads the wall clock. A
blocked run fails with the reason in the job summary and writes no snapshot. An
accepted run rotates data/latest_snapshot.json into data/previous_snapshot.json,
commits the new snapshot to main, and dispatches the Pages deploy.
Dead-Man's Switch
After every run, including failed ones, the workflow asks the Actions API for the
last 30 runs of daily_sync.yml. If the current run failed and the failure run
reaches three in a row, it opens an issue labelled dead-mans-switch (or comments
on the existing one) with the run link. The next passing run closes that issue.
The alert path needs no extra secret because GITHUB_TOKEN is scoped by the
issues: write permission already declared on the job.
Hugging Face sync
sync_hf.yml exports the dataset on a weekly schedule and uploads it to
llmcostledger/llm-pricing-snapshot when the repository secret HF_TOKEN is
set. The job and the upload step are both marked continue-on-error: true, the
outcome is written to the run summary, and nothing downstream depends on it: a
missing token or a failed upload leaves the daily sync and the Pages deploy
untouched.
Promotion and rollback
Builds are artifacts, data is committed, and every deploy is reproducible from a commit, so a rollback is a revert rather than a repair.
- Pages. Deployments are listed under the
github-pagesenvironment, which keeps the previous one. To roll back:git revert <data commit>and push, which redeploys, or rungh workflow run deploy_pages.yml --ref <branch-or-tag>. - Snapshot data. Every accepted snapshot keeps its predecessor in
data/previous_snapshot.json. Reverting the data commit restores both files. - PyPI. Published versions are immutable. Fix forward with a higher patch version; if a release is broken, yank it in the PyPI UI instead of deleting it.
- Container. Images are addressed by tag; redeploying the previous tag or digest is the rollback. The base image is pinned by tag and digest, so a rebuild resolves to the same filesystem.
Container
docker build -t llmcostledger:0.1.0 .
docker run --rm llmcostledger:0.1.0 calc --model openai/gpt-4o
A two-stage build installs the package into a virtual environment in the builder
stage and copies only that environment into the runtime stage. The runtime runs
as uid 10001, and the image health check is llmcostledger verify, which reads
the bundled seed snapshot and exits non-zero when a sanity check fails.
Local checks
The canonical commands are run from the repository root:
PYTHONPATH=./src python -m pytest ./tests --basetemp=./.pytest_tmp -v
ruff check ./src ./tests
./repro_fresh.sh [python-binary] repeats the checks from a clean copy: it
creates its own virtual environment, installs the package into a throwaway target
with --no-index, then runs the suite, the CLI and the dataset export from a
directory outside the repository. Optional extras already installed for the given
interpreter are put on the path so the Parquet path runs too. It never modifies
the checkout and prints the work directory it keeps.
Repository layout
pyproject.toml
src/llmcostledger/ package modules and data/snapshot_seed.json
tests/ pytest suite
.github/workflows/ the four workflows above
data/ snapshots written by daily_sync (data/ appears after the first sync)
Dockerfile two-stage, non-root image
repro_fresh.sh offline reproduction script
Metadata
Release files for llmcostledger 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 |
|---|---|---|---|---|
| llmcostledger-0.1.0.tar.gz | 115.9 kB | With provenance | Details for llmcostledger-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| llmcostledger-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for llmcostledger-0.1.0-py3-none-any.whl |
Total release size: 203.1 kB
Release files / llmcostledger-0.1.0.tar.gz
| Download URL | llmcostledger-0.1.0.tar.gz |
|---|---|
| Size | 115.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f299349802a06528f77049685349987ae1e2ebd4408340e2e8621cac7a9f3baf
|
|
BLAKE2b-256 checksum How to use checksums |
02148024a3cc48b9b2b929fbc2cb97057ab74c0c0789dce8732e43d2a94ff70f
|
| 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 Dec 4, 2026.
Transparency logRelease files / llmcostledger-0.1.0-py3-none-any.whl
| Download URL | llmcostledger-0.1.0-py3-none-any.whl |
|---|---|
| Size | 87.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bb23ee15e91a440b7496cdf8113eb0439f67ca3843be66d0eaddbf9a95fbc8b0
|
|
BLAKE2b-256 checksum How to use checksums |
4bbbdfb5485dd3b04f19445d5ed697129cb742bb01e84a070f92b611925f6720
|
| 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 Dec 4, 2026.
Transparency logSecurity for llmcostledger 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 llmcostledger-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 Dec 4, 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.