Database of prices for calling LLM models.
Project description
genai-prices
Python package for github.com/pydantic/genai-prices.
This method calculates the price of API calls to a range of LLM inference providers.
Installation
uv add genai-prices
(or pip install genai-prices if you're old school)
Usage
Since this library may need to make a network call to download prices, both sync and async veriants of calc_price are provided.
Sync API Example
from genai_prices import Usage, calc_price_sync
price_data = calc_price_sync(
Usage(input_tokens=1000, output_tokens=100),
model_ref='gpt-4o',
provider_id='openai',
)
print(price_data.price)
Async API Example
import asyncio
from genai_prices import Usage, calc_price_async
async def main():
price_data = await calc_price_async(
Usage(input_tokens=1000, output_tokens=100),
model_ref='gpt-4o',
provider_id='openai',
)
print(price_data.price)
if __name__ == '__main__':
asyncio.run(main())
Auto Update
Both calc_price_sync and calc_price_async can be configured to auto-update by passing auto_update=True as an argument.
This will cause the library to periodically check for updates to the price data.
Please note:
- this functionality is explicitly opt-in
- we download data directly from GitHub (
https://raw.githubusercontent.com/pydantic/genai-prices/refs/heads/main/prices/data.json) so we don't and can't monitor requests or gather telemetry
You may also pass a custom source to auto_update to customize auto-update behavior.
At the time of writing, the data.json file
downloaded by auto-update is around 26KB when compressed, so is generally very quick to download.
None-the-less, the library tries hard to avoid making a network call when the user calls
calc_price_sync or calc_price_async:
- data is cached for one hour by default
- when the cached data is 30minutes old, the library will attempt to update the cache in the background
- You may pre-fetch data at program startup using
genai_prices.prefetch_async()andgenai_prices.prefetch_sync(), these are both sync methods which return immediately and update the cache in the background, the only difference is thatcalc_price_asyncwill wait for theprefetch_asynctask to complete when it is first called, andcalc_price_syncwill wait for theprefetch_syncconcurrent future to complete when it is first called.
Further Documentation
We do not yet build API documentation for this package, but the source code is relatively simple and well documented.
If you need further information on the API, we encourage you to read the source code.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file genai_prices-0.0.1.tar.gz.
File metadata
- Download URL: genai_prices-0.0.1.tar.gz
- Upload date:
- Size: 38.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.7.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89d664647d75c3e5659cae8ab0d7ef862976c5cdea169fb6b1b460bd0491ae06
|
|
| MD5 |
fcbeaa5f12f5c373444371bfea27d5f2
|
|
| BLAKE2b-256 |
6df404821754c584475f2b38913727d9d2f7619c8d22b60d8e0218b4bddd6200
|
File details
Details for the file genai_prices-0.0.1-py3-none-any.whl.
File metadata
- Download URL: genai_prices-0.0.1-py3-none-any.whl
- Upload date:
- Size: 39.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.7.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
758438413a39582d7beb02ec1339ae61f917a3a2676af4e604b95b3ed796314e
|
|
| MD5 |
66ad6b6a394dd8e73f8567ee299e7d28
|
|
| BLAKE2b-256 |
16e76d47af570ae576a692616d03bc1a1f7308c7a5c7ed127f367cd410cd82ef
|