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.1 and requires Python 3.10 or later.
Installation
Install the latest release from PyPI:
pip install txaion-model-pricing
For local development, clone the repository and install it with the development dependencies:
python -m pip install -e ".[dev]"
Quick start
from txaion_model_pricing import (
calculate_cost,
count_models,
get_available_token_price_fields,
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")
priority_cost = calculate_cost(
"azure_ai/gpt-5.5",
1_000_000,
"input_cost_per_token_priority",
)
print(input_cost) # Decimal("2.5000000")
print(output_cost) # Decimal("10.00000")
print(cached_cost) # Decimal("1.25000000")
print(priority_cost) # Decimal("10.00000")
details = get_model_details("gpt-4o")
print(details["max_input_tokens"])
fields = get_available_token_price_fields("azure_ai/gpt-5.5")
print("input_cost_per_token_priority" in fields) # True
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.
In addition to the three aliases, token_type may be a raw scalar per-token
price field present in the model snapshot, such as
input_cost_per_token_priority, output_cost_per_reasoning_token, or
cache_creation_input_token_cost. Fields priced per character, image, second,
page, request, or session are not accepted, even when their names mention a
token threshold.
get_available_token_price_fields(model) -> tuple[str, ...]
Returns a stable, sorted tuple of the raw scalar per-token price fields available for the model. Use this discovery API before selecting optional or provider-specific pricing fields.
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:
# The field name is valid, but this model does not provide that price.
...
except (InvalidTokenCountError, InvalidTokenTypeError):
# The token count or price-field name is invalid.
...
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.1only calculates costs from scalar per-token fields. - Image-, character-, second-, page-, request-, session-, search-, tool-call-,
and storage-based pricing are not supported by
calculate_cost(). Token fields for audio content are supported when the snapshot expresses their unit as a per-token price. - 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.1.tar.gz.
File metadata
- Download URL: txaion_model_pricing-0.1.1.tar.gz
- Upload date:
- Size: 94.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49cc180829e394aca39e296049a1d366d860c88226104fcdbb4e1d295606a19b
|
|
| MD5 |
93a361ac03616502036e7568f9d6ccfd
|
|
| BLAKE2b-256 |
4acad54e02cc6a3d615448a48eef416a6e8d4868b2ebc5284d957a5af74de856
|
Provenance
The following attestation bundles were made for txaion_model_pricing-0.1.1.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.1.tar.gz -
Subject digest:
49cc180829e394aca39e296049a1d366d860c88226104fcdbb4e1d295606a19b - Sigstore transparency entry: 2255217754
- Sigstore integration time:
-
Permalink:
txaion/txaion-model-pricing@e6ed13d94704bbcf394cf94a84be481fbf5b9834 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/txaion
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e6ed13d94704bbcf394cf94a84be481fbf5b9834 -
Trigger Event:
release
-
Statement type:
File details
Details for the file txaion_model_pricing-0.1.1-py3-none-any.whl.
File metadata
- Download URL: txaion_model_pricing-0.1.1-py3-none-any.whl
- Upload date:
- Size: 91.0 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 |
192ce1bc415ca0e4fdd5b8e02404bca315144560623d30e5d951e6040145f95a
|
|
| MD5 |
91a0e3816b829395edc0b947aca5690b
|
|
| BLAKE2b-256 |
25a074784bc77d3ff380594780c1fd47c2b6cba951b8579d96501d64dde96dc1
|
Provenance
The following attestation bundles were made for txaion_model_pricing-0.1.1-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.1-py3-none-any.whl -
Subject digest:
192ce1bc415ca0e4fdd5b8e02404bca315144560623d30e5d951e6040145f95a - Sigstore transparency entry: 2255217758
- Sigstore integration time:
-
Permalink:
txaion/txaion-model-pricing@e6ed13d94704bbcf394cf94a84be481fbf5b9834 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/txaion
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e6ed13d94704bbcf394cf94a84be481fbf5b9834 -
Trigger Event:
release
-
Statement type: