tokenary
Calculate LLM API cost estimates in USD from LiteLLM pricing data.
Use the bundled offline snapshot, generate a catalog for selected models, or
opt into asynchronous price updates. calculate() is synchronous and performs
no network I/O.
Install
Requires Python 3.13 or newer.
pip install tokenary
Calculate a cost
from tokenary import calculate
result = calculate(model="gpt-4o", input_tokens=1000, output_tokens=500)
print(result.total_cost)
print(result.model_dump()) # Category breakdown and pricing checksums
No setup or generation is needed. The default uses prices shipped with the installed version, opens requested providers and validates models on demand.
Input and output counts are inclusive totals: reasoning, audio and cache
counts are subsets. A requested category without a supported rate raises
MissingPriceError. See usage and billing rules.
Choose your pricing source
| Need | Use | Guide |
|---|---|---|
| Start immediately, fully offline | calculate(...) with bundled prices |
Usage |
| Pin prices or select specific models | Generate a catalog and pass catalog=CATALOG |
Custom catalogs |
| Refresh prices in a running application | await prices.get_catalog() on a LivePricingCatalog |
Live pricing |
For example, generate a small Python catalog:
tokenary-generate --models gpt-4o o1 --output my_prices.py
from tokenary import calculate
from my_prices import CATALOG, ModelName
result = calculate(
model=ModelName.GPT_4O,
input_tokens=1000,
output_tokens=500,
catalog=CATALOG,
)
Without --input, generation downloads the current
LiteLLM catalog
once. It does not update the installed default. JSON and gzip catalogs are
supported too.
Find the details
- Documentation index — guides, reference and runnable examples.
- Usage reference — request fields, adapters, cache and context tiers.
- Development — setup, checks and catalog regeneration.
- Snapshot provenance — bundled source, checksum and refresh summary.
- Migration notes and performance.
- Changelog — release changes and intentional breaking changes.
- Agent instructions — repository map, invariants and verification.
Review history and completed implementation tickets live in tickets/.
Metadata
Release files for tokenary 0.2.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 |
|---|---|---|---|---|
| tokenary-0.2.0.tar.gz | 1.1 MB | Without provenance | Details for tokenary-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tokenary-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for tokenary-0.2.0-py3-none-any.whl |
Total release size: 1.4 MB
Release files / tokenary-0.2.0.tar.gz
| Download URL | tokenary-0.2.0.tar.gz |
|---|---|
| Size | 1.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6eb575d8a4fcfd62ba66289e69ead93b28b621b009a75fe5e8f1cf0deef20cae
|
|
BLAKE2b-256 checksum How to use checksums |
1dc3965b7614a1d2ee3dfe8a462e018d22338a8bd12c34138e0766e97aaf796c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.2
|
Release files / tokenary-0.2.0-py3-none-any.whl
| Download URL | tokenary-0.2.0-py3-none-any.whl |
|---|---|
| Size | 364.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3db6d752190a7097384b06d418dcde924b2c28dedb297fbbdc2c2f1bfd735b11
|
|
BLAKE2b-256 checksum How to use checksums |
cb3da7046e59b332c5eee456cd4f888e74304e598a51b3bf7638fed7a463c7dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.2
|
Security for tokenary 0.2.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.