Skip to content

pydantic/genai-prices

Repository files navigation

GenAI Prices

CI Coverage PyPI versions license Join Slack

Calculate prices for calling LLM inference APIs.

🛠️ Work in Progress

This package is a work in progress:

  • price data YAML
  • JSON file with all prices
  • Python library with functionality to calculate prices, including opt-in support for phoning home to get latest prices
  • JS/TS library with functionality to calculate prices, including opt-in support for phoning home to get latest prices
  • Beta release workflow with changesets for versioning and publishing
  • API (and I guess UI) for calculating latest prices

Features

  • Advanced logic for matching on model IDs to maximise the chance of using the correct model
  • Support for historic prices and prices changes, e.g. we have the prices for o3 before and after it's price changed
  • Support for variable daily prices, e.g. we support calculating deepseek prices even with off-peak pricing
  • tiered pricing support for Gemini models where you pay a separate price for very large contexts
  • support for identifying price discrepancies from other sources
  • Python package, CLI
  • JavaScript/TypeScript package, CLI
  • TODO: API and web UI

Providers

The following providers are currently supported:

Usage

Python Package & CLI

See the Python README for instructions on how to install and use the Python package and CLI.

JavaScript/TypeScript Package

See the JS/TS README for instructions on how to install and use the JavaScript/TypeScript package and CLI.

Download data

Price data is available in the following files:

Feel free to download these files and use them as you wish. We would be grateful if you would reference this project wherever you use it and contribute back to the project if you find any errors.

Release Workflow

This project uses changesets for versioning and publishing:

  • Stable releases: Automatically published when PRs are merged to main (if changesets are present)
  • Beta releases: Use the GitHub Actions workflow "Beta Release" to:
    • Enter beta mode: Creates a PR to enable beta releases
    • Version packages: Creates a PR with new beta versions
    • Exit beta mode: Creates a PR to disable beta releases and prepare for stable release

API

Coming soon...

⚠️ Warning: these prices will not be 100% accurate

This project is a best effort from Pydantic and the community to provide an indicative estimate of the price you might pay for calling an LLM.

The price data cannot be exactly correct because model providers do not provide exact price information for their APIs in a format which can be reliably processed.

If you get a bill you weren't expecting, don't blame us!

If you're a lawyer, please read the LICENSE under which this project is developed, hosted and distributed.

If you're a developer, please contribute to fix any missing or incorrect prices you find.

Contributing

We welcome contributions from the community and especially model/inference providers!

If you're a model provider: it would be amazing if you would serve a JSON file or API endpoint with pricing information which we could pull from. You would be the first AFAIK, and I think it would dramatically improve the experience for developers using your API!

Otherwise, to contribute:

  • See prices/README.md for instructions on how to contribute to the price data.
  • Feel free to submit pull requests or issues about the Python and JS packages.
  • If you need a library for another language, please create an issue, we'd be happy to discuss building it, hosting it here, or helping you maintain it elsewhere.

Thanks

This project would not be possible without the following existing data sources:

While none of these sources had exactly what we needed (hence creating this project), they (especially helicone) were used to populate some of the initial price database, and we continue to pull price updates from them.

Thanks to all those projects!

About

Calculate prices for calling LLM inference APIs.

Resources

License

Security policy

Stars

Watchers

Forks

Contributors 5