Calculate LLM token costs from llmlite pricing data
Project description
llmcalc
llmcalc is a typed Python library and CLI for estimating LLM token costs.
Install
pip install llmcalc
What It Does
- Resolves model pricing from an upstream pricing source.
- Calculates input, output, and total costs with deterministic decimal rounding.
- Provides a small Python API and a CLI.
- Caches pricing data locally (default TTL:
43200seconds).
Cost Formula
total = (input_tokens * input_price_per_token) + (output_tokens * output_price_per_token)
Pricing is pulled from llmlite model pricing data and cached locally.
Python Quickstart
from llmcalc import cost
result = cost(
model="gpt-5.1",
input_tokens=1200,
output_tokens=800,
)
if result is not None:
print(result.total_cost, result.currency)
You can also calculate from usage-style objects via usage(...).
Async variants are available as cost_async(...) and usage_async(...).
CLI Quickstart
# cost quote from token counts
llmcalc quote --model gpt-5.1 --input 1200 --output 800
# inspect per-token pricing for one model
llmcalc model --model gpt-5.1 --json
# clear local cache
llmcalc cache clear
# show version
llmcalc --version
llmcalc -v
Configuration
LLMCALC_CACHE_TIMEOUT: cache TTL in seconds (default43200)LLMCALC_PRICING_URL: override pricing source URLLLMCALC_CURRENCY: fallback currency label if upstream omits currency
Maintainers
Contributor workflows and release validation live in AGENTS.md.
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 llmcalc-0.1.1.tar.gz.
File metadata
- Download URL: llmcalc-0.1.1.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5a04ab9e886ef741785d7a6a8f05740217dd4243ce45637ce62a9be35c66a19
|
|
| MD5 |
66fabae58b0af6c765b84f8d85e745c4
|
|
| BLAKE2b-256 |
4faa94348c9c3197fb00b79607eb68c9250c14a9b42ef6412aab72cafed43e34
|
File details
Details for the file llmcalc-0.1.1-py3-none-any.whl.
File metadata
- Download URL: llmcalc-0.1.1-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0085d0c0f056669799f92373e1b52f43ff96657c09caab517ec5ace70efdf78
|
|
| MD5 |
5d4db16beacaa5bbbe791aef315ffeee
|
|
| BLAKE2b-256 |
cf5a71055bddb24a21a6f4f7dbe0e136dd4c8f979d979a8afaaf4e6599f27419
|