pydantic/genai-prices
Calculate prices for calling LLM inference APIs.
📊 GenAI Prices – What It Is
GenAI Prices is a small but practical open‑source library that lets developers look up how much it should cost to call a given large‑language‑model (LLM) inference endpoint. It ships:
- Data – a curated, versioned JSON registry of pricing rules for hundreds of models across dozens of providers (OpenAI, Anthropic, Azure, Bedrock, Gemini, etc.). The data includes historic rates, tiered pricing, off‑peak discounts and even per‑token‑type costs.
- Logic – code that matches a user‑supplied provider‑ID and model‑ID to the correct entry, handling quirks like renamed models or provider‑specific pricing schemes.
- Clients – ready‑to‑use packages for Python, JavaScript/TypeScript, and Go, each exposing a tiny API (
get_price(...)) and a command‑line tool (genai-prices) for quick look‑ups. - Extensibility – the repository encourages contributions of new providers or price updates, and it already pulls data from sources such as Helicone, LiteLLM and OpenRouter.
The project is part of the Pydantic Stack, which aims to give developers a type‑safe, production‑ready foundation for AI agents.
🔧 Key Features (as listed in the README)
| Feature | What It Means |
|---|---|
| Advanced matching logic | Tries hard to map the exact provider/model you specify to the correct price entry, even when IDs differ slightly. |
| Historic & changing prices | Stores old rates (e.g., for o1) so you can see how costs evolved over time. |
| Variable daily pricing | Supports providers that change rates by time of day (e.g., Deepseek off‑peak pricing). |
| Tiered pricing for Gemini | Handles separate charges for very large context windows. |
| Price‑discrepancy detection | Tools to compare the registry against other public sources. |
| Multi‑language packages | Python, JS/TS, and Go libraries + CLIs. |
| Future API & web UI | Planned, but not yet released. |
📦 How to Use It
Python
pip install genai-prices
Then in code:
from genai_prices import get_price
price = get_price(provider="openai", model="gpt-4o", tokens=1000)
print(price) # → {'input': 0.005, 'output': 0.015, 'currency': 'USD'}
The accompanying CLI (genai-prices) mirrors this functionality from the terminal.
JavaScript/TypeScript
npm i @pydantic/genai-prices
import { getPrice } from '@pydantic/genai-prices'
const price = getPrice({ provider: 'anthropic', model: 'claude-3-opus', tokens: 500 })
console.log(price)
A genai-prices command is also provided.
Go
go get github.com/pydantic/genai-prices/go
price, _ := genaiprices.GetPrice("openrouter", "meta-llama/Meta-Llama-3.1-70B-Instruct", 2000)
fmt.Println(price)
📂 Data Files
- v2 (current) –
prices/new_data/v2/data.json(full) anddata_slim.json(free‑model‑stripped, smaller). Schemas are provided. - v1 – frozen legacy files kept for backward compatibility.
You can download these JSON files directly and embed them in your own tooling if you prefer not to depend on the library.
🤝 Contributing & Community
- Submit price updates via pull requests (see
prices/README.md). - Benchmark the price‑lookup performance (
benchmarks/README.md). - If you run a model‑hosting service, you’re encouraged to expose a JSON or API endpoint with your pricing so the project can ingest it.
- Join the Pydantic Slack (badge link in the README) for discussion.
⚠️ Accuracy Disclaimer
The authors stress that the numbers are indicative only. Providers rarely publish machine‑readable price tables, so the data is assembled from public docs, community contributions, and other open‑source price lists. Always verify against your actual provider bill.
📚 Where It Fits
GenAI Prices fills a niche gap for developers building LLM‑driven applications, cost‑monitoring dashboards, or budgeting tools. By providing a single, type‑safe source of pricing information across the fragmented LLM ecosystem, it helps avoid surprise bills and makes cost‑aware prompting easier.
Related
- Project
- Project
- Project
- Dispatch
- Project