Skip to main content

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.

PyPI Python License: MIT

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/pricing
get_model(model_id, currency=) GET /api/v1/pricing/{model_id}
get_history(days=, model_id=, provider=) GET /api/v1/pricing/history
get_providers() GET /api/v1/pricing/providers
compare(model_ids, currency=) GET /api/v1/pricing/compare
get_cheapest(provider=, currency=) GET /api/v1/pricing/cheapest

Types

All types are dataclass(slots=True) for performance and type safety:

  • ModelPricing — model pricing data
  • CostEstimate — cost calculation result
  • PriceHistoryPoint — historical price data point
  • ModelHistory — price history for a model
  • ProviderSummary — provider overview with stats
  • PriceTokenError — API error (extends Exception)

Type aliases: ModelStatus, DataConfidence, Source (all Literal types).

Requirements

  • Python >= 3.10
  • Zero runtime dependencies

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pricetoken-0.3.0.tar.gz (28.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pricetoken-0.3.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file pricetoken-0.3.0.tar.gz.

File metadata

  • Download URL: pricetoken-0.3.0.tar.gz
  • Upload date:
  • Size: 28.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

Hashes for pricetoken-0.3.0.tar.gz
Algorithm Hash digest
SHA256 4497e9ab5b5644be7d1258e043d95aae952bb1ab311c90b3998b5973663496b1
MD5 d0fe047792f569b283516e0a76262f5d
BLAKE2b-256 44f8ea5e228c8858b280d7a6516862d62ce98c57dda6d4f47e18c83d36e51f2b

See more details on using hashes here.

File details

Details for the file pricetoken-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: pricetoken-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 7.6 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

Hashes for pricetoken-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9c60d7d6fa3534bcfb3d9f23603af970e1cdfc8639bb6e0291b0c59fbf4935d9
MD5 add1c012b396d43041ee2a0b736ac670
BLAKE2b-256 36199b974241c78720974cc76f823e12bf62721186aabfcdeb5c4edd50ec10a1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page