pydantic/genai-prices

Calculate prices for calling LLM inference APIs.

What it is

GenAI Prices is an open‑source library that collects, curates, and serves pricing information for dozens of large‑language‑model (LLM) inference APIs. It lets developers look up how much a token, request, or context length will cost on providers such as OpenAI, Anthropic, Gemini, Azure, and many others.

Why it matters

When you build an AI product you often need to estimate or control spend. Providers publish prices in different formats (some change daily, some have tiered rates, some offer historic price revisions). Keeping this data up‑to‑date manually is error‑prone. GenAI Prices centralises the data, normalises the model‑and‑provider identifiers, and offers a programmatic way to calculate costs, helping teams budget, compare providers, and spot pricing anomalies.

Core features

  • Extensive provider coverage – 40+ providers, 1 500+ models, with YAML files that map provider‑specific IDs to a common schema.
  • Historical & variable pricing – supports price changes over time and daily‑varying rates (e.g., Deepseek off‑peak pricing).
  • Tiered pricing – handles models where cost depends on context size (e.g., Gemini large‑context tiers).
  • Discrepancy detection – tools to compare the library’s numbers with other sources.
  • Multi‑language SDKs – ready‑to‑use packages and CLIs for Python, JavaScript/TypeScript, and Go.
  • Data files – static JSON registries (full and slim versions) that can be downloaded and used without the SDKs.
  • Future API & web UI – roadmap includes a hosted service for on‑the‑fly look‑ups.

Who should use it

  • Developers building LLM‑powered apps who need to estimate token costs for budgeting or pricing their own services.
  • Product managers comparing providers to choose the most cost‑effective option.
  • Ops / finance teams that want to audit cloud‑LLM spend and catch unexpected price changes.
  • LLM providers who can contribute their own pricing files to keep the registry accurate.

Getting started

  1. Install the SDK – e.g. pip install genai-prices (Python) or npm i genai-prices (JS/TS).
  2. Load the price registry – the package ships the JSON data; you can also download the raw files from the prices/ directory.
  3. Query a model – call the helper function with a provider name, model ID, and token count to receive a cost estimate.
  4. Use the CLI – genai-prices lookup openai/gpt-4 1000 prints the cost for 1 000 tokens.
  5. Contribute – add or update a provider’s YAML file, run the benchmark workflow, and submit a PR.

Limitations & caveats

  • Best‑effort data – prices are scraped/curated from public sources; they may lag behind provider updates or miss region‑specific discounts.
  • No real‑time API yet – the library currently relies on static JSON files; an online API is planned.
  • Only inference pricing – training‑time costs, fine‑tuning fees, or custom enterprise contracts are out of scope.

GenAI Prices is part of the Pydantic Stack, which also includes Pydantic AI (type‑safe agent framework), Logfire observability, and an AI gateway.

Related

  • Project
  • Project
  • Project
  • Project