genai_get_pricing
This page explains how to use the genai_get_pricing function in APL.
The genai_get_pricing function retrieves the pricing information for a specific AI model. It returns a dynamic object containing the input token price and output token price per million tokens, which you can use for cost calculations and budgeting.
You can use this function to display pricing information, create cost calculators, audit pricing data, or understand the cost structure of different AI models.
Usage
Syntax
genai_get_pricing(model)Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | The name of the AI model (for example, 'gpt-4', 'claude-3-opus-20240229', 'gpt-3.5-turbo'). |
Returns
Returns a dynamic object containing pricing information with the following structure:
{
"input_price_per_million": <number>,
"output_price_per_million": <number>
}Returns null if the model isn't recognized.
Example
Get pricing information for a GenAI model to understand cost structure.
Query
['otel-demo-genai']
| extend model = ['attributes.gen_ai.request.model']
| extend pricing = genai_get_pricing(model)
| where isnotnull(pricing)
| summarize request_count = count() by model, pricing = tostring(pricing)
| top 3 by request_countOutput
| model | pricing | request_count |
|---|---|---|
| gpt-4 | {"input_price_per_million": 30.0, "output_price_per_million": 60.0} | 450 |
| gpt-3.5-turbo | {"input_price_per_million": 0.5, "output_price_per_million": 1.5} | 1250 |
This query shows which models are being used and their associated pricing, helping teams make informed decisions.
List of related functions
- genai_cost: Calculates total cost for a conversation. Use this for actual cost calculation after retrieving pricing information.
- genai_input_cost: Calculates input token cost. This function uses genai_get_pricing internally to determine input costs.
- genai_output_cost: Calculates output token cost. This function uses genai_get_pricing internally to determine output costs.
- genai_estimate_tokens: Estimates token count. Combine with pricing information to predict costs before making API calls.