Registry / llm-agents / genai-prices

genai-prices

JSON →
library0.1.4pypypi✓ verified 25d ago

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-prices
INSTALL
IMPORT
SIG · GENAI-PRICES
G
genai-prices
llm-agentspythonv0.1.4
Install
3.8s avg
Import
660ms
Disk
31MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.694s · 32.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.8s · import 0.626s · 33MB
31MB installed
● package 31MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

calc_price
from genai_prices import calc_price
from genai_prices import get_model_price
Usage
from genai_prices import Usage
update_prices
from genai_prices import update_prices

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.

from genai_prices import get_model_price, TokenUsage from decimal import Decimal model_name = "gpt-4o" usage = TokenUsage( input_tokens=1000, output_tokens=1000, ) price_info = get_model_price(model_name, usage) if price_info: print(f"Model: {model_name}") print(f"Provider: {price_info.provider}") print(f"Input price per 1k tokens: ${price_info.input_cost_per_token_1k}") print(f"Output price per 1k tokens: ${price_info.output_cost_per_token_1k}") print(f"Total cost: ${price_info.total_cost:.6f}") else: print(f"Price for model '{model_name}' not found.")
Debug
Known issues
gotchaModel names and pricing are frequently updated. Relying on exact string matches for models can be brittle. It's recommended to keep the library updated to ensure you have the latest model aliases and pricing information.
fix
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.
affects: <0.0.56
breakingAs of v0.0.54, the library introduced 'model lifecycle management' meaning models can be explicitly marked as deprecated or removed. If you rely on a model that is subsequently removed, `get_model_price` will return `None`.
fix
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.
affects: >=0.0.54
gotchaAWS Bedrock model matching logic was loosened in v0.0.55/v0.0.56 to support inference profiles and regional models. This change might alter which specific model is matched if your input string is ambiguous, potentially leading to different price calculations.
fix
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.
affects: >=0.0.55
gotchaOlder versions (pre-v0.0.50) might have had incorrect tiered pricing calculations, as a fix for this was included in v0.0.50.
fix
Upgrade to `genai-prices` v0.0.50 or newer to ensure accurate tiered pricing calculations.
affects: <0.0.50
breakingThe `get_model_price` function is no longer directly importable from the `genai_prices` package, leading to an `ImportError`.
fix
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.
affects: >=0.0.57
breakingThe `get_model_price` function is no longer directly importable from the top-level `genai_prices` package. It has likely been moved, renamed, or replaced by functions such as `get_model_price_and_alias`.
fix
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.
affects: >0.0.56
Upgrade
Version history
0.1.4latest on PyPI · released Aug 19, 2026
Audit
Dependencies
pydanticrequiredCore data validation and settings management, >=2.0
pydantic-settingsrequiredUsed for managing configurations, >=2.0
httpxrequiredAsynchronous HTTP client used for fetching pricing data, >=0.24.0,<0.28.0
richoptionalUsed for rich output in the CLI, >=13.0,<14.0
typeroptionalUsed for building the command-line interface, >=0.9.0,<0.13.0
Agent activity
47 hits · last 30 days
node
42
Perplexity
1
OpenAI (training)
1
Resources
genai-prices — pip install genai-prices · libregistry