Skip to main content
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.
| lookup model_pricing model OUTPUT input_price output_price
In ANSI SQL, you would join with a pricing table to get model costs.
SELECT 
  l.*,
  p.input_price,
  p.output_price
FROM ai_logs l
JOIN model_pricing p ON l.model = p.model_name

Usage

Syntax

genai_get_pricing(model)

Parameters

  • model (string, required): 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.

Use case examples

  • Log analysis
  • OpenTelemetry traces
  • Security logs
Display pricing information for models being used to help teams understand cost implications.Query
['sample-http-logs']
| where uri contains '/api/openai'
| extend model_name = tostring(todynamic(response_body)['model'])
| extend pricing = genai_get_pricing(model_name)
| where isnotnull(pricing)
| summarize request_count = count() by model_name, pricing = tostring(pricing)
Run in PlaygroundOutput
model_namepricingrequest_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.