# genai-prices

> Calculate prices for calling LLM inference APIs.

- **URL**: https://www.freshcrate.ai/projects/genai-prices
- **Author**: Samuel Colvin
- **Category**: Frameworks
- **Latest version**: `v0.0.63` (2026-06-05)
- **License**: Unknown
- **Source**: https://github.com/pydantic/genai-prices/releases
- **Homepage**: https://pypi.org/project/genai-prices/
- **Language**: Python
- **GitHub**: 282 stars, 58 forks
- **Registry**: pypi (`genai-prices`)
- **Tags**: `pypi`

## Description

<div align="center">
  <h1>genai-prices</h1>
</div>
<div align="center">
  <a href="https://github.com/pydantic/genai-prices/actions/workflows/ci.yml?query=branch%3Amain"><img src="https://github.com/pydantic/genai-prices/actions/workflows/ci.yml/badge.svg?event=push" alt="CI"></a>
  <a href="https://coverage-badge.samuelcolvin.workers.dev/redirect/pydantic/genai-prices"><img src="https://coverage-badge.samuelcolvin.workers.dev/pydantic/genai-prices.svg" alt="Coverage"></a>
  <a href="https://pypi.python.org/pypi/genai-prices"><img src="https://img.shields.io/pypi/v/genai-prices.svg" alt="PyPI"></a>
  <a href="https://github.com/pydantic/genai-prices"><img src="https://img.shields.io/pypi/pyversions/genai-prices.svg" alt="versions"></a>
  <a href="https://github.com/pydantic/genai-prices/blob/main/LICENSE"><img src="https://img.shields.io/github/license/pydantic/genai-prices.svg" alt="license"></a>
  <a href="https://logfire.pydantic.dev/docs/join-slack/"><img src="https://img.shields.io/badge/Slack-Join%20Slack-4A154B?logo=slack" alt="Join Slack" /></a>
</div>

<br/>
<div align="center">
  Python package for <a href="https://github.com/pydantic/genai-prices">github.com/pydantic/genai-prices</a>.
</div>
<br/>

## Installation

```bash
uv add genai-prices
```

(or `pip install genai-prices` if you're old school)

To use the CLI with Rich output/help, install the optional CLI dependencies:

```bash
uv add "genai-prices[cli]"
```

(or `pip install "genai-prices[cli]"`)

## Warning: these prices will not be 100% accurate

See [the project README](https://github.com/pydantic/genai-prices?tab=readme-ov-file#warning) for more information.

## Usage

### `calc_price`

```python
from genai_prices import Usage, calc_price

price_data = calc_price(
    Usage(input_tokens=1000, output_tokens=100),
    model_ref='gpt-4o',
    provider_id='openai',
)
print(f"Total Price: ${price_data.total_price} (input: ${price_data.input_price}, output: ${price_data.output_price})")
```

### `extract_usage`

`extract_usage` can be used to extract usage data and the `model_ref` from response data,
which in turn can be used to calculate prices:

```py
from genai_prices import extract_usage

response_data = {
    'model': 'claude-sonnet-4-20250514',
    'usage': {
        'input_tokens': 504,
        'cache_creation_input_tokens': 123,
        'cache_read_input_tokens': 0,
        'output_tokens': 97,
    },
}
extracted_usage = extract_usage(response_data, provider_id='anthropic')
price = extracted_usage.calc_price()
print(price.total_price)
```

or with OpenAI where there are two API flavors:

```py
from genai_prices import extract_usage

response_data = {
    'model': 'gpt-5',
    'usage': {'prompt_tokens': 100, 'completion_tokens': 200},
}
extracted_usage = extract_usage(response_data, provider_id='openai', api_flavor='chat')
price = extracted_usage.calc_price()
print(price.total_price)
```

### `UpdatePrices`

`UpdatePrices` can be used to periodically update the price data by downloading it from GitHub

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

At the time of writing, the `data.json` file
downloaded by `UpdatePrices` is around 26KB when compressed, so is generally very quick to download.

By default `UpdatePrices` downloads price data immediately after it's started in the background, then every hour after that.

Usage with `UpdatePrices` as as context manager:

```py
from genai_prices import UpdatePrices, Usage, calc_price

with UpdatePrices() as update_prices:
    update_prices.wait()  # optionally wait for prices to have updated
    p = calc_price(Usage(input_tokens=123, output_tokens=456), 'gpt-5')
    print(p)
```

Usage with `UpdatePrices` as a simple class:

```py
from genai_prices import UpdatePrices, Usage, calc_price

update_prices = UpdatePrices()
update_prices.start(wait=True)  # start updating prices, optionally wait for prices to have updated
p = calc_price(Usage(input_tokens=123, output_tokens=456), 'gpt-5')
print(p)
update_prices.stop()  # stop updating prices
```

Only one `UpdatePrices` instance can be running at a time.

If you'd like to wait for prices to be updated without access to the `UpdatePrices` instance, you can use the `wait_prices_updated_sync` function:

```py
from genai_prices import wait_prices_updated_sync

wait_prices_updated_sync()
...
```

Or it's async variant, `wait_prices_updated_async`.

### CLI Usage

Run the CLI with:

```bash
uvx genai-prices --help
```

Or, if installed locally, make sure CLI extras are present:

```bash
pip install "genai-prices[cli]"
genai-prices --help
```

If local CLI extras are not installed, the command will print an install hint for `genai-prices[cli]`.

To list providers and models, run:

```bash
uvx genai-prices list
```

To calculate the price of models, run f

## Recent releases

| Version | Date | Urgency | Changes |
| --- | --- | --- | --- |
| `v0.0.63` | 2026-06-05 | High | ## What's Changed * Add Claude Opus 4.8 pricing by @dsfaccini in https://github.com/pydantic/genai-prices/pull/389 * Update deepseek-v4-pro to new permanent pricing by @MarkusWendorf in https://github.com/pydantic/genai-prices/pull/391 * Google and Mistral AI models on AWS by @mahiuchun in https://github.com/pydantic/genai-prices/pull/392 * Prep 0.0.63 release by @dmontagu in https://github.com/pydantic/genai-prices/pull/393  ## New Contributors * @MarkusWendorf made their first contribution in |
| `v0.0.62` | 2026-05-25 | High | ## What's Changed * feat: add Gemini 3.5 Flash pricing by @dsfaccini in https://github.com/pydantic/genai-prices/pull/379 * Drop Python 3.9 support by @alexmojaki in https://github.com/pydantic/genai-prices/pull/380 * Consolidate Python CLI implementation by @alexmojaki in https://github.com/pydantic/genai-prices/pull/382 * Improve Python test coverage by @alexmojaki in https://github.com/pydantic/genai-prices/pull/381 * Add amazon provider match for aws by @Yun-Kim in https://github.com/py |
| `v0.0.61` | 2026-05-19 | High | ## What's Changed * chore: update gpt-5.5 aliases by @ddanielcruzz in https://github.com/pydantic/genai-prices/pull/376 * Prep 0.0.61 release by @ddanielcruzz in https://github.com/pydantic/genai-prices/pull/377   **Full Changelog**: https://github.com/pydantic/genai-prices/compare/v0.0.60...v0.0.61 |
| `v0.0.60` | 2026-05-15 | High | ## What's Changed * Introduce zizmor by @Viicos in https://github.com/pydantic/genai-prices/pull/362 * Fix npm release publishing by @SmileMachine in https://github.com/pydantic/genai-prices/pull/363 * Support GA version of Gemini 3.1 Flash-Lite by @mahiuchun in https://github.com/pydantic/genai-prices/pull/366 * Fix Google tool-use prompt token count mapping by @alexmojaki in https://github.com/pydantic/genai-prices/pull/370 * Split independent pricing fixes by @alexmojaki in https://githu |
| `v0.0.59` | 2026-05-07 | High | ## What's Changed * Add OpenRouter date-suffixed Claude 4.5 model aliases by @nirnaim in https://github.com/pydantic/genai-prices/pull/319 * Keep `_background_task` alive to update_prices after failed attempts by @adtyavrdhn in https://github.com/pydantic/genai-prices/pull/323 * Update OpenRouter Claude 4.6 pricing and add dated aliases by @nirnaim in https://github.com/pydantic/genai-prices/pull/320 * Add Nvidia Nemotron Bedrock models pricing by @rian-dolphin in https://github.com/pydantic |
| `0.0.57` | 2026-04-21 | Low | Imported from PyPI (0.0.57) |
| `v0.0.56` | 2026-03-20 | Low | ## What's Changed * feat: add gpt-5.3-codex pricing by @sigglep in https://github.com/pydantic/genai-prices/pull/301 * feat: add Gemini 3.1 Flash Lite (Preview) pricing by @rian-dolphin in https://github.com/pydantic/genai-prices/pull/302 * feat: refactor python cli with rich output and pydantic-settings by @Else00 in https://github.com/pydantic/genai-prices/pull/278 * Loosen matchers for regional-only AWS Claude 3.* models by @alexmojaki in https://github.com/pydantic/genai-prices/pull/305 |
| `v0.0.56` | 2026-03-20 | Low | ## What's Changed * feat: add gpt-5.3-codex pricing by @sigglep in https://github.com/pydantic/genai-prices/pull/301 * feat: add Gemini 3.1 Flash Lite (Preview) pricing by @rian-dolphin in https://github.com/pydantic/genai-prices/pull/302 * feat: refactor python cli with rich output and pydantic-settings by @Else00 in https://github.com/pydantic/genai-prices/pull/278 * Loosen matchers for regional-only AWS Claude 3.* models by @alexmojaki in https://github.com/pydantic/genai-prices/pull/305 |
| `v0.0.56` | 2026-03-20 | Low | ## What's Changed * feat: add gpt-5.3-codex pricing by @sigglep in https://github.com/pydantic/genai-prices/pull/301 * feat: add Gemini 3.1 Flash Lite (Preview) pricing by @rian-dolphin in https://github.com/pydantic/genai-prices/pull/302 * feat: refactor python cli with rich output and pydantic-settings by @Else00 in https://github.com/pydantic/genai-prices/pull/278 * Loosen matchers for regional-only AWS Claude 3.* models by @alexmojaki in https://github.com/pydantic/genai-prices/pull/305 |
| `v0.0.56` | 2026-03-20 | Low | ## What's Changed * feat: add gpt-5.3-codex pricing by @sigglep in https://github.com/pydantic/genai-prices/pull/301 * feat: add Gemini 3.1 Flash Lite (Preview) pricing by @rian-dolphin in https://github.com/pydantic/genai-prices/pull/302 * feat: refactor python cli with rich output and pydantic-settings by @Else00 in https://github.com/pydantic/genai-prices/pull/278 * Loosen matchers for regional-only AWS Claude 3.* models by @alexmojaki in https://github.com/pydantic/genai-prices/pull/305 |

## Citation

- HTML: https://www.freshcrate.ai/projects/genai-prices
- Markdown: https://www.freshcrate.ai/projects/genai-prices.md
- Dependencies JSON: https://www.freshcrate.ai/api/projects/genai-prices/deps

_Generated by freshcrate.ai. Indexes pypi releases for AI-agent ecosystem packages._
