genai-prices is a Python library for calculating the cost of interacting with various Large Language Model (LLM) inference APIs. It aggregates pricing information from major providers like OpenAI, Anthropic, Google, AWS Bedrock, and more. The library is actively maintained by Pydantic, with frequent minor releases (typically weekly or bi-weekly) to keep pricing data and model definitions up-to-date.
pip install genai-pricesVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to use `get_model_price` to calculate the cost for a given model and token usage. It prints the per-1k-token costs and the total cost. If the model is not found, it prints a message.
Regularly update the `genai-prices` library (`pip install --upgrade genai-prices`) and consider using the `genai-prices models` CLI command or `get_model_price_and_alias` function (if available) to verify model names.
Implement error handling for `None` returns from `get_model_price` and ensure your application can gracefully handle models being retired. Consult provider documentation for active models or use the library's CLI (`genai-prices models`) to check current status.
Test your existing model name inputs with the updated library to confirm the correct model is being matched. Use specific and unambiguous model names where possible, or inspect the `ModelInfo` returned to verify the matched provider and model ID.
Upgrade to `genai-prices` v0.0.50 or newer to ensure accurate tiered pricing calculations.
Update your code to reflect the new import path or function name for model price retrieval. Consult the official `genai-prices` documentation or release notes for the correct API usage in the installed version.
Update your imports to reflect the new location or name of the price retrieval function. Consult the latest `genai-prices` documentation or source code, and consider using `get_model_price_and_alias` if it fits your needs.