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.

For users of other query languages

If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.

In Splunk SPL, you would typically use a lookup table to retrieve pricing information by model name.

```sql Splunk example | lookup model_pricing model OUTPUT input_price output_price ```
['ai-logs']
| extend pricing = genai_get_pricing(model)

In ANSI SQL, you would join with a pricing table to get model costs.

```sql SQL example SELECT l.*, p.input_price, p.output_price FROM ai_logs l JOIN model_pricing p ON l.model = p.model_name ```
['ai-logs']
| extend pricing = genai_get_pricing(model)

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 is not 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_count

Run in Playground

Output

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.

  • 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.

Good morning

I'm here to help you with the docs.

I
AIBased on your context