Skip to main content

llm-price

Pricing + release metadata and cost estimation for LLMs (OpenAI + Google Gemini).

Features

  • Model metadata with release dates
  • Static pricing in USD per 1M tokens
  • Cost estimation from token counts or raw text
  • Any currency output (real-time FX from exchangerate.host, cached)
  • CLI for listing models and summing JSONL usage

Install

pip install llm-price

Quickstart (Python)

from decimal import Decimal

from llm_price import cost_from_text, cost_from_tokens, get_fx_rate, list_models

models = list_models("openai")
print(models[0])

cost = cost_from_text(
    "openai",
    "gpt-4o-mini",
    prompt="Summarize this text.",
    completion="Here is a summary...",
)
print(cost.total_cost)

cost_in_inr = cost_from_tokens(
    "google",
    "gemini-1.5-flash",
    prompt_tokens=120,
    completion_tokens=40,
    currency="INR",
    fx_rate=Decimal("83.12"),
)
print(cost_in_inr.total_cost)

live_fx = get_fx_rate("USD", "INR")
print("Live USD→INR:", live_fx)

CLI

llm-price models --provider openai

llm-price cost \
  --provider openai \
  --model gpt-4o-mini \
  --prompt "Hello" \
  --completion "Hi" \
  --currency USD

llm-price cost \
  --provider google \
  --model gemini-1.5-flash \
  --prompt-tokens 100 \
  --completion-tokens 20 \
  --currency INR \
  --fx-rate "83.12"

JSONL Summation

llm-price sum usage.jsonl supports lines with:

Token counts

{"provider":"openai","model":"gpt-4o-mini","prompt_tokens":1200,"completion_tokens":400}

Raw text (tokenized internally)

{"provider":"openai","model":"gpt-4o-mini","prompt":"Hello","completion":"Hi"}

Pre-computed totals

{"total_cost":{"amount":"0.0123","currency":"USD"}}

Example Scripts

Run these from the repo root after installing dependencies:

python examples/basic_cost.py
python examples/inr_conversion.py
python examples/sum_jsonl.py

Notes

  • Pricing data is stored in src/llm_price/data/models.json in USD per 1M tokens.
  • OpenAI pricing is refreshed daily from https://bes-dev.github.io/openai-pricing-api/pricing.json via a GitHub Actions workflow.
  • OpenAI entries also store cached_input_per_1m when available.
  • For non-USD output, FX defaults to a real-time rate from exchangerate.host.
  • You can override it with fx_rate to use a fixed rate.
  • Rates are cached in-process for 1 hour by default.
  • Gemini token counting uses the official CountTokens API when GOOGLE_API_KEY is set; otherwise it falls back to an approximation.

Development

pip install -e ".[dev]"
pytest

Release (PyPI)

This project uses GitHub Actions trusted publishing. Create a tag like v0.1.0 and push it to GitHub to trigger the publish workflow:

git tag v0.1.0
git push origin v0.1.0

Configure the PyPI Trusted Publisher with:

  • PyPI Project Name: llm-price
  • Owner: VA24d
  • Repository name: API-price
  • Workflow name: publish.yml
  • Environment name: pypi

Metadata

Release files for llm-price 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llm-price 0.1.3
File Size Uploaded
llm_price-0.1.3.tar.gz 9.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for llm-price 0.1.3
File Interpreter ABI Platform
llm_price-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 19.4 kB

Release files / llm_price-0.1.3.tar.gz

Download URL llm_price-0.1.3.tar.gz
Size 9.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b5e9a04447f160d7d90e27c08e0b2923da23aff7600741cf76750cba6a1bd5b2
BLAKE2b-256 checksum
How to use checksums
582f9f2e8b9f944624ea33a2ef3320567a25ab55e1f4ab03d839241160c5daed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Feb 9, 2026.

Transparency log

Release files / llm_price-0.1.3-py3-none-any.whl

Download URL llm_price-0.1.3-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a154dee16f164791eb9bf3a30d9c4dfdd4eee8ebeb0f2c93d4eefc95901fb5af
BLAKE2b-256 checksum
How to use checksums
7aead074e1c5d406c0e54e3000bf5872946b9b7493ba4dd621af062aab58b2cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Feb 9, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page