### Install and Run CLI Locally Source: https://github.com/pydantic/genai-prices/blob/main/packages/python/README.md Install the genai-prices package with CLI extras and then run the help command. If local CLI extras are not installed, the command will print an install hint. ```bash pip install "genai-prices[cli]" genai-prices --help ``` -------------------------------- ### Install genai-prices Source: https://github.com/pydantic/genai-prices/blob/main/packages/python/README.md Install the genai-prices package using uv or pip. ```bash uv add genai-prices ``` -------------------------------- ### Install genai-prices with CLI dependencies Source: https://github.com/pydantic/genai-prices/blob/main/packages/python/README.md Install genai-prices with optional CLI dependencies for Rich output and help. ```bash uv add "genai-prices[cli]" ``` -------------------------------- ### Install Dependencies and Pre-commit Hooks Source: https://github.com/pydantic/genai-prices/blob/main/CLAUDE.md Run this command to install project dependencies and set up pre-commit hooks for automated code checks. ```bash make install ``` -------------------------------- ### List All Available Providers and Models Source: https://github.com/pydantic/genai-prices/blob/main/packages/js/README.md Use the `list` command with the globally installed `genai-prices` to see all supported providers and their models. ```bash genai-prices list ``` -------------------------------- ### Calculate GenAI Prices with Global Install Source: https://github.com/pydantic/genai-prices/blob/main/packages/js/README.md Calculate the price for a model using the globally installed `genai-prices` command, specifying input and output tokens. ```bash genai-prices gpt-5 --input-tokens 1000 --output-tokens 100 ``` -------------------------------- ### Install Pydantic GenAI Prices Globally Source: https://github.com/pydantic/genai-prices/blob/main/packages/js/README.md Install the package globally using npm to make the `genai-prices` command available system-wide. ```bash npm i -g @pydantic/genai-prices ``` -------------------------------- ### List Providers and Models Source: https://github.com/pydantic/genai-prices/blob/main/packages/python/README.md Use this command to get a list of supported AI providers and their available models. ```bash uvx genai-prices list ``` -------------------------------- ### Get LiteLLM Prices Source: https://github.com/pydantic/genai-prices/blob/main/CLAUDE.md Downloads pricing data specifically from the LiteLLM source. ```bash make litellm-get ``` -------------------------------- ### Get Simon Willison's Prices Source: https://github.com/pydantic/genai-prices/blob/main/CLAUDE.md Downloads pricing data from Simon Willison's price list. ```bash make simonw-prices-get ``` -------------------------------- ### Get OpenRouter Prices Source: https://github.com/pydantic/genai-prices/blob/main/CLAUDE.md Downloads pricing data specifically from the OpenRouter source. ```bash make openrouter-get ``` -------------------------------- ### Get Helicone Prices Source: https://github.com/pydantic/genai-prices/blob/main/CLAUDE.md Downloads pricing data specifically from the Helicone source. ```bash make helicone-get ``` -------------------------------- ### Update Data Files with Make Build Source: https://github.com/pydantic/genai-prices/blob/main/prices/README.md Run this command from the repository root to manually update the `data*.json` files. Ensure `pre-commit` is installed. ```bash make build ``` -------------------------------- ### Run Latest Package via npx Source: https://github.com/pydantic/genai-prices/blob/main/packages/js/README.md Execute the latest version of the package directly using npx without global installation. ```bash npx @pydantic/genai-prices@latest ``` -------------------------------- ### Update Prices as a Simple Class Source: https://github.com/pydantic/genai-prices/blob/main/packages/python/README.md Manage price updates using the UpdatePrices class directly. Start, wait, perform calculations, and then stop the updater. ```python 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 ``` -------------------------------- ### Get and Update Price Discrepancies Source: https://github.com/pydantic/genai-prices/blob/main/prices/README.md Execute this command to download the latest prices from external sources and inject discrepancies into YAML files. By default, it targets models with outdated or missing price check dates. ```bash make get-update-price-discrepancies ``` -------------------------------- ### Extract Usage Data for Anthropic Source: https://github.com/pydantic/genai-prices/blob/main/packages/python/README.md Use extract_usage to get usage data and model reference from response data for Anthropic models. ```python 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) ``` -------------------------------- ### Extract Usage Data for OpenAI Chat API Source: https://github.com/pydantic/genai-prices/blob/main/packages/python/README.md Use extract_usage to get usage data and model reference from response data for OpenAI chat API. Specify api_flavor='chat'. ```python 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) ``` -------------------------------- ### Display CLI Help Source: https://github.com/pydantic/genai-prices/blob/main/packages/python/README.md Run this command to see all available options and commands for the genai-prices CLI. ```bash uvx genai-prices --help ``` -------------------------------- ### Prepare Data for Packages Source: https://github.com/pydantic/genai-prices/blob/main/CLAUDE.md This command prepares the pricing data for inclusion in the published packages. ```bash make package-data ``` -------------------------------- ### Download Prices from All External Sources Source: https://github.com/pydantic/genai-prices/blob/main/CLAUDE.md Fetches pricing information from all configured external pricing data sources. ```bash make get-all-prices ``` -------------------------------- ### List Available GenAI Models with npx Source: https://github.com/pydantic/genai-prices/blob/main/packages/js/README.md Use npx to list all available AI models supported by the package. ```bash npx @pydantic/genai-prices@latest list ``` -------------------------------- ### Build JSON Schema and Validate/Write Price Data Source: https://github.com/pydantic/genai-prices/blob/main/CLAUDE.md Generates the JSON schema, validates pricing data, and writes it to prices/data.json. This command should be run after editing provider YAML files. ```bash make build-prices ``` -------------------------------- ### Update Prices using Context Manager Source: https://github.com/pydantic/genai-prices/blob/main/packages/python/README.md Use UpdatePrices as a context manager to automatically download and update price data. Optionally wait for updates. ```python 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) ``` -------------------------------- ### Run Tests with Coverage Source: https://github.com/pydantic/genai-prices/blob/main/CLAUDE.md Executes the test suite and generates a coverage report to show which parts of the code are tested. ```bash make test ``` -------------------------------- ### Calculate Model Prices Source: https://github.com/pydantic/genai-prices/blob/main/packages/python/README.md Calculate the cost of using AI models based on input and output tokens. Specify the number of tokens and the model names. ```bash uvx genai-prices calc --input-tokens 100000 --output-tokens 3000 o1 o3 claude-opus-4 ``` -------------------------------- ### Download and Update Price Discrepancies Source: https://github.com/pydantic/genai-prices/blob/main/CLAUDE.md Fetches current price discrepancies and updates the local records. ```bash make get-update-price-discrepancies ``` -------------------------------- ### Check for Price Discrepancies Source: https://github.com/pydantic/genai-prices/blob/main/CLAUDE.md Compares current pricing data against external sources to identify any discrepancies. ```bash make check-for-price-discrepancies ``` -------------------------------- ### Specify Provider for Price Calculation Source: https://github.com/pydantic/genai-prices/blob/main/packages/js/README.md When calculating prices, explicitly specify the provider along with the model name. ```bash genai-prices openai:gpt-5 --input-tokens 1000 --output-tokens 100 ``` -------------------------------- ### Calculate GenAI Prices with npx Source: https://github.com/pydantic/genai-prices/blob/main/packages/js/README.md Use npx to calculate the price for a specific model by providing input and output token counts. ```bash npx @pydantic/genai-prices@latest calc gpt-4 --input-tokens 1000 --output-tokens 500 ``` -------------------------------- ### Run Tests and Generate HTML Coverage Report Source: https://github.com/pydantic/genai-prices/blob/main/CLAUDE.md Runs tests and produces an HTML report detailing code coverage, useful for identifying untested areas. ```bash make testcov ``` -------------------------------- ### Handle missing pricing information Source: https://github.com/pydantic/genai-prices/blob/main/packages/js/README.md The library returns null when a model or provider cannot be matched, allowing for explicit error handling. ```js import { calcPrice } from '@pydantic/genai-prices' const usage = { input_tokens: 1000, output_tokens: 100 } // Returns null if model/provider not found const result = calcPrice(usage, 'non-existent-model') if (result === null) { console.log('No pricing information available for this model') } else { console.log(`Total Price: $${result.total_price} (input: $${result.input_price}, output: $${result.output_price})`) } // Async version also returns null const asyncResult = await calcPrice(usage, 'non-existent-model', { awaitAutoUpdate: true, providerId: 'unknown-provider' }) if (asyncResult === null) { console.log('No pricing information available for this model/provider combination') } else { console.log(`Total Price: $${asyncResult.total_price} (input: $${asyncResult.input_price}, output: $${asyncResult.output_price})`) } ``` -------------------------------- ### Update project version Source: https://github.com/pydantic/genai-prices/blob/main/RELEASE.md Execute the version update script with the target version as an argument. ```bash ./uprev.sh ``` -------------------------------- ### List Models for a Specific Provider Source: https://github.com/pydantic/genai-prices/blob/main/packages/js/README.md Filter the list of available models to show only those from a specific provider. ```bash genai-prices list openai ``` -------------------------------- ### Format Code with Ruff Source: https://github.com/pydantic/genai-prices/blob/main/CLAUDE.md Applies code formatting rules using ruff to ensure consistent style across the project. ```bash make format ``` -------------------------------- ### Update Local Packages and Lock File Source: https://github.com/pydantic/genai-prices/blob/main/CLAUDE.md Use this command to synchronize local package versions with the lock file. ```bash make sync ``` -------------------------------- ### Test Across Python Versions Source: https://github.com/pydantic/genai-prices/blob/main/CLAUDE.md Runs the full test suite across multiple Python versions (3.10-3.13) to ensure compatibility. ```bash make test-all-python ``` -------------------------------- ### Calculate Price with calc_price Source: https://github.com/pydantic/genai-prices/blob/main/packages/python/README.md Use calc_price to determine the cost of AI model usage. Requires Usage object, model reference, and provider ID. ```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})") ``` -------------------------------- ### Update pricing data asynchronously Source: https://github.com/pydantic/genai-prices/blob/main/packages/js/README.md Ensure the latest pricing data is used by awaiting the update process before calling calcPrice. ```ts import { calcPrice, updatePrices } from '@pydantic/genai-prices' enableAutoUpdate(/** auto-update logic */) // ... // this guarantees that the latest data is used await waitForUpdate() const result = calcPrice(usage, 'gpt-5', { providerId: 'openai' }) console.log( `$${result.total_price} (input: $${result.input_price}, output: $${result.output_price})`, result.provider.name, result.model.name ) ``` -------------------------------- ### Synchronously Wait for Price Updates Source: https://github.com/pydantic/genai-prices/blob/main/packages/python/README.md Use wait_prices_updated_sync to block until price data has been updated without needing an UpdatePrices instance. ```python from genai_prices import wait_prices_updated_sync wait_prices_updated_sync() ... ``` -------------------------------- ### Define custom pricing models Source: https://github.com/pydantic/genai-prices/blob/main/packages/js/README.md Pass a custom provider object to calcPrice to calculate costs for models not included in the default catalog. ```ts import { calcPrice, Provider } from '@pydantic/genai-prices' const customProvider: Provider = { id: 'custom-provider', name: 'Custom Provider', api_pattern: '.*', models: [ { id: 'my-new-model', match: { equals: 'my-new-model' }, prices: { input_mtok: 2.5, output_mtok: 10.0, }, }, ], } const usage = { input_tokens: 1000, output_tokens: 100 } const result = calcPrice(usage, 'my-new-model', { provider: customProvider }) ``` -------------------------------- ### Run Static Type Checking Source: https://github.com/pydantic/genai-prices/blob/main/CLAUDE.md Performs static type checking using basedpyright to catch type-related errors. ```bash make typecheck ``` -------------------------------- ### Check Code Style and Linting Source: https://github.com/pydantic/genai-prices/blob/main/CLAUDE.md Executes linting checks to identify and report style violations and potential code issues. ```bash make lint ``` -------------------------------- ### Calculate API prices with calcPrice Source: https://github.com/pydantic/genai-prices/blob/main/packages/js/README.md Use the calcPrice function to compute costs based on token usage and model identifiers. It returns a result object containing price details or null if the model is not found. ```ts import { calcPrice } from '@pydantic/genai-prices' const usage = { input_tokens: 1000, output_tokens: 100 } const result = calcPrice(usage, 'gpt-3.5-turbo', { providerId: 'openai' }) if (result) { console.log( `$${result.total_price} (input: $${result.input_price}, output: $${result.output_price})`, result.provider.name, result.model.name ) } else { console.log('No price found for this model/provider combination') } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.