Real-time LLM pricing data — typed client, cost calculator, and static pricing
Project description
pricetoken
Real-time LLM pricing data — typed client, cost calculator, and static pricing.
Python SDK for PriceToken. Zero runtime dependencies.
Install
pip install pricetoken
# or
uv add pricetoken
Quick Start
Calculate cost offline (no API call)
from pricetoken import calculate_model_cost
cost = calculate_model_cost("claude-sonnet-4-6", 1_000_000, 100_000)
print(cost.total_cost) # $4.50
Fetch live pricing
from pricetoken import PriceTokenClient
client = PriceTokenClient()
pricing = client.get_pricing()
for model in pricing:
print(f"{model.display_name}: ${model.input_per_m_tok}/MTok in, ${model.output_per_m_tok}/MTok out")
With API key (higher rate limits)
client = PriceTokenClient(api_key="pt_your_key_here")
Cost Calculation
from pricetoken import calculate_cost, calculate_model_cost
# By model ID (uses bundled static pricing)
cost = calculate_model_cost("gpt-4.1", 500_000, 100_000)
print(cost.input_cost) # $1.00
print(cost.output_cost) # $0.80
print(cost.total_cost) # $1.80
# With explicit rates
cost = calculate_cost("custom-model", 5.0, 15.0, 1_000_000, 500_000)
print(cost.total_cost) # $12.50
Static Pricing Data
21 models from Anthropic, OpenAI, Google, and DeepSeek are bundled for offline use:
from pricetoken import STATIC_PRICING
for model in STATIC_PRICING:
print(f"{model.model_id}: ${model.input_per_m_tok}/MTok")
API Reference
| Method | API Path |
|---|---|
get_pricing(provider=, currency=) |
GET /api/v1/text |
get_model(model_id, currency=) |
GET /api/v1/text/{model_id} |
get_history(days=, model_id=, provider=) |
GET /api/v1/text/history |
get_providers() |
GET /api/v1/text/providers |
compare(model_ids, currency=) |
GET /api/v1/text/compare |
get_cheapest(provider=, currency=) |
GET /api/v1/text/cheapest |
Types
All types are dataclass(slots=True) for performance and type safety:
ModelPricing— model pricing dataCostEstimate— cost calculation resultPriceHistoryPoint— historical price data pointModelHistory— price history for a modelProviderSummary— provider overview with statsPriceTokenError— API error (extendsException)
Type aliases: ModelStatus, DataConfidence, Source (all Literal types).
Requirements
- Python >= 3.10
- Zero runtime dependencies
License
MIT
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 pricetoken-0.7.0.tar.gz.
File metadata
- Download URL: pricetoken-0.7.0.tar.gz
- Upload date:
- Size: 35.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
813719f8e8895a252cfc59450428e657ade4d9f3e062086abf07594a4c6c94f5
|
|
| MD5 |
bae3d42b7bb1548f44f1389e675f7684
|
|
| BLAKE2b-256 |
a71477f019199509b4110d0eb2e44fff78f3004e42e2b4d1be0b6960d9a9af42
|
File details
Details for the file pricetoken-0.7.0-py3-none-any.whl.
File metadata
- Download URL: pricetoken-0.7.0-py3-none-any.whl
- Upload date:
- Size: 14.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f98f3fe0b7bce7ce5a7ea1465baedeee5141a3815c9159b5c44b1e925895f195
|
|
| MD5 |
ccb0962070a1f30f479ac7673a2250c9
|
|
| BLAKE2b-256 |
d770aaa062307c386360bf0e1266608774c298cb3d4bdc395c9ddec03959b25f
|