Cross-provider AI model pricing for Python
Project description
Txaion Model Pricing
Lightweight, cross-provider model pricing for Python.
English | 繁體中文
Txaion Model Pricing is a lightweight Python package for querying
cross-provider model information and calculating USD costs for input, output,
and cached-input tokens.
Developed and maintained by Txaion.
The current version is 0.1.0 and requires Python 3.10 or later.
Installation
Install the package from the project directory:
python -m pip install .
Install the development dependencies for testing and building:
python -m pip install -e ".[dev]"
Quick start
from txaion_model_pricing import calculate_cost, count_models, get_model_details
print(count_models())
input_cost = calculate_cost("gpt-4o", 1_000_000, "input")
output_cost = calculate_cost("gpt-4o", 1_000_000, "output")
cached_cost = calculate_cost("gpt-4o", 1_000_000, "cached")
print(input_cost) # Decimal("2.5000000")
print(output_cost) # Decimal("10.00000")
print(cached_cost) # Decimal("1.25000000")
details = get_model_details("gpt-4o")
print(details["max_input_tokens"])
All costs are returned as decimal.Decimal values. The package does not round
results or perform currency conversion.
Public API
count_models() -> int
Returns the number of models in the bundled snapshot. Metadata entries such as
sample_spec are excluded.
calculate_cost(model, tokens, token_type) -> Decimal
Calculates the USD cost using the model's per-token price:
inputmaps toinput_cost_per_tokenoutputmaps tooutput_cost_per_tokencachedmaps tocache_read_input_token_cost
tokens must be a non-negative integer. If the requested price field is
unavailable, the package does not treat the cost as zero or fall back to a
different price.
get_model_details(model) -> dict
Returns a deep copy of the model data. Modifying the returned value does not affect the package's internal cache.
Error handling
All domain-specific exceptions inherit from ModelPriceError:
from txaion_model_pricing import (
InvalidTokenCountError,
InvalidTokenTypeError,
NotFound,
PriceUnavailableError,
calculate_cost,
)
try:
cost = calculate_cost("unknown-model", 1_000, "input")
except NotFound:
...
except PriceUnavailableError:
...
except (InvalidTokenCountError, InvalidTokenTypeError):
...
Price data
The package includes a pinned snapshot of the
LiteLLM model price and context-window data.
The source commit, retrieval time, and SHA-256 checksum are recorded in
src/txaion_model_pricing/data_source.json. See THIRD_PARTY_NOTICES.md for
third-party attribution and licensing information.
Maintainers must specify an immutable commit SHA or tag when updating the snapshot:
python scripts/update_prices.py <commit-or-tag>
The update tool downloads and validates the JSON before atomically replacing
the snapshot and its metadata. Moving refs such as main, master, and
latest are rejected.
Limitations
- Version
0.1.0only calculates token-based input, output, and cached-input costs. - Image, audio, search, tool-call, session, and storage pricing are not
supported by
calculate_cost(). - Model providers may change their prices at any time. Results depend on the bundled snapshot and may not match current provider pricing. Verify official provider prices before using the results for billing or budget enforcement.
Development
ruff check .
pytest
python -m build
License
This project and the vendored LiteLLM data are redistributed under the MIT
License. See LICENSE and THIRD_PARTY_NOTICES.md for details.
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 txaion_model_pricing-0.1.0.tar.gz.
File metadata
- Download URL: txaion_model_pricing-0.1.0.tar.gz
- Upload date:
- Size: 90.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f7cea1c07a0d4792344fa092993bbb64ab79d3ee158a3e8aabbddf45f5086e6
|
|
| MD5 |
852a03e96fe376ee91f98f025728886a
|
|
| BLAKE2b-256 |
3d02c331b021572b1b39641e3de81aa7ec3be8cc19bc5098c9415b1c96e6fbc6
|
Provenance
The following attestation bundles were made for txaion_model_pricing-0.1.0.tar.gz:
Publisher:
publish.yml on txaion/txaion-model-pricing
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
txaion_model_pricing-0.1.0.tar.gz -
Subject digest:
2f7cea1c07a0d4792344fa092993bbb64ab79d3ee158a3e8aabbddf45f5086e6 - Sigstore transparency entry: 2255183086
- Sigstore integration time:
-
Permalink:
txaion/txaion-model-pricing@a8f78db581aff5fc4834d3fe5706773e65c4cec3 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/txaion
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a8f78db581aff5fc4834d3fe5706773e65c4cec3 -
Trigger Event:
release
-
Statement type:
File details
Details for the file txaion_model_pricing-0.1.0-py3-none-any.whl.
File metadata
- Download URL: txaion_model_pricing-0.1.0-py3-none-any.whl
- Upload date:
- Size: 86.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d65f85de67fda1ccd4f754d696a11aa7724e722076480e16ce8f421eb624da2
|
|
| MD5 |
bb6b91e5c90b549783fec73912a5ff27
|
|
| BLAKE2b-256 |
d71489c0adf58d413e303138512fa838395802d222400ad0db6e48014d8d0c6e
|
Provenance
The following attestation bundles were made for txaion_model_pricing-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on txaion/txaion-model-pricing
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
txaion_model_pricing-0.1.0-py3-none-any.whl -
Subject digest:
4d65f85de67fda1ccd4f754d696a11aa7724e722076480e16ce8f421eb624da2 - Sigstore transparency entry: 2255183089
- Sigstore integration time:
-
Permalink:
txaion/txaion-model-pricing@a8f78db581aff5fc4834d3fe5706773e65c4cec3 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/txaion
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a8f78db581aff5fc4834d3fe5706773e65c4cec3 -
Trigger Event:
release
-
Statement type: