LLM Model Cost Calculator
A Python package to calculate token costs for various LLM models based on input and output tokens.
Prices come from LiteLLM's public model_prices_and_context_window.json, fetched on first use.
Installation
pip install llm_model_cost
https://pypi.org/project/llm-model-cost/
Usage
from llm_model_cost import ModelCost
# Calculate cost for a model
costInfo = ModelCost(name="gpt-4o", input_tokens=1000, output_tokens=500)
# Get cost details
print(f"Input cost: ${costInfo.input_cost:.6f}")
print(f"Output cost: ${costInfo.output_cost:.6f}")
print(f"Total cost: ${costInfo.cost:.6f}")
# Prompt caching: input_tokens is the FULL prompt, cached_tokens the subset served from cache
# OpenAI: input_tokens=usage.prompt_tokens, cached_tokens=usage.prompt_tokens_details.cached_tokens
# Anthropic: input_tokens=input_tokens + cache_read_input_tokens + cache_creation_input_tokens,
# cached_tokens=cache_read_input_tokens, cache_creation_tokens=cache_creation_input_tokens
costInfo = ModelCost(name="gpt-4o", input_tokens=10_000, output_tokens=500, cached_tokens=8_000)
print(costInfo.uncached_input_cost, costInfo.cached_input_cost, costInfo.cache_creation_cost)
# Get model information
model_info = ModelCost.get_model_info("gpt-4o")
print(f"Max tokens: {model_info['max_tokens']}")
print(f"Provider: {model_info['litellm_provider']}")
# List all available models
models = ModelCost.list_models()
How the cost is computed
input_cost = uncached_tokens * input_rate + cached_tokens * cache_read_rate + cache_creation_tokens * cache_creation_rateoutput_cost = output_tokens * output_rate(reasoning tokens are part ofoutput_tokens)- Long-context tiers (
*_above_200k_tokensetc.) apply to the whole request onceinput_tokensexceeds the threshold, matching provider billing. - Models with no cache price bill cached tokens at the normal input rate (no discount known).
ValueErroris raised for unknown models, models not priced per token (image / audio / TTS), negative counts, orcached_tokens + cache_creation_tokens > input_tokens.
Not covered: batch / flex / priority service tiers, per-image / per-second / per-character pricing, tool-call surcharges (web search, code interpreter).
Features
- Calculate token costs for various LLM models, including prompt-cache reads/writes
- Get model information including max tokens, costs, and provider details
- List all available models and their capabilities
- Automatic updates from the latest pricing data
Development
python -m unittest discover tests
Metadata
Release files for llm-model-cost 1.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 | |
|---|---|---|---|---|
| llm_model_cost-1.1.0.tar.gz | 6.6 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| llm_model_cost-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.7 kB
Release files / llm_model_cost-1.1.0.tar.gz
| Download URL | llm_model_cost-1.1.0.tar.gz |
|---|---|
| Size | 6.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1d608610f25236e14c5ce63b63398a29edb494c8097aab468817f0661f9d5472
|
|
BLAKE2b-256 checksum How to use checksums |
5f88a878d0a652564c8bc3a0c281988c6b8e4f3e5c6f2481faa06031a0771eb9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 17, 2026.
Transparency logRelease files / llm_model_cost-1.1.0-py3-none-any.whl
| Download URL | llm_model_cost-1.1.0-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ed97bc3456bd575bf1d6f24f27f0b983cc01550807f9ec2111cd2f4e2d60fa8f
|
|
BLAKE2b-256 checksum How to use checksums |
53bce0eef5ce582a3bd553878a18f1599abe51bf4ba0b51bf6de20b3877ce2e8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 17, 2026.
Transparency logSecurity for llm-model-cost 1.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
All 2 files in this release have been uploaded with provenance metadata.
Attestation for llm_model_cost-1.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 Sep 17, 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.