{"id":1488,"library":"genai-prices","title":"genai-prices","description":"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.","status":"active","version":"0.0.56","language":"en","source_language":"en","source_url":"https://github.com/pydantic/genai-prices","tags":["AI","LLM","pricing","cost","models","generative-ai"],"install":[{"cmd":"pip install genai-prices","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Core data validation and settings management, >=2.0","package":"pydantic","optional":false},{"reason":"Used for managing configurations, >=2.0","package":"pydantic-settings","optional":false},{"reason":"Asynchronous HTTP client used for fetching pricing data, >=0.24.0,<0.28.0","package":"httpx","optional":false},{"reason":"Used for rich output in the CLI, >=13.0,<14.0","package":"rich","optional":true},{"reason":"Used for building the command-line interface, >=0.9.0,<0.13.0","package":"typer","optional":true}],"imports":[{"symbol":"get_model_price","correct":"from genai_prices import get_model_price"},{"symbol":"TokenUsage","correct":"from genai_prices import TokenUsage"},{"note":"Top-level imports are preferred for core components; ModelInfo is exposed directly via `__init__.py`.","wrong":"from genai_prices.model_info import ModelInfo","symbol":"ModelInfo","correct":"from genai_prices import ModelInfo"}],"quickstart":{"code":"from genai_prices import get_model_price, TokenUsage\nfrom decimal import Decimal\n\nmodel_name = \"gpt-4o\"\nusage = TokenUsage(\n    input_tokens=1000,\n    output_tokens=1000,\n)\nprice_info = get_model_price(model_name, usage)\n\nif price_info:\n    print(f\"Model: {model_name}\")\n    print(f\"Provider: {price_info.provider}\")\n    print(f\"Input price per 1k tokens: ${price_info.input_cost_per_token_1k}\")\n    print(f\"Output price per 1k tokens: ${price_info.output_cost_per_token_1k}\")\n    print(f\"Total cost: ${price_info.total_cost:.6f}\")\nelse:\n    print(f\"Price for model '{model_name}' not found.\")","lang":"python","description":"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."},"warnings":[{"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.","message":"Model 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.","severity":"gotcha","affected_versions":"<0.0.56"},{"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.","message":"As 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`.","severity":"breaking","affected_versions":">=0.0.54"},{"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.","message":"AWS 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.","severity":"gotcha","affected_versions":">=0.0.55"},{"fix":"Upgrade to `genai-prices` v0.0.50 or newer to ensure accurate tiered pricing calculations.","message":"Older versions (pre-v0.0.50) might have had incorrect tiered pricing calculations, as a fix for this was included in v0.0.50.","severity":"gotcha","affected_versions":"<0.0.50"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}