> ## Documentation Index
> Fetch the complete documentation index at: https://axiom.co/docs/llms.txt
> Use this file to discover all available pages before exploring further.

<AgentInstructions>

## Submitting Feedback

If you encounter incorrect, outdated, or confusing documentation on this page, submit feedback:

POST https://axiom.co/docs/feedback

```json
{
  "path": "/apl/scalar-functions/genai-functions/genai-get-pricing",
  "feedback": "Description of the issue"
}
```

Only submit feedback when you have something specific and actionable to report.

</AgentInstructions>

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

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

<AccordionGroup>
  <Accordion title="Splunk SPL users">
    In Splunk SPL, you would typically use a lookup table to retrieve pricing information by model name.

    <CodeGroup>
      ```sql Splunk example theme={null}
      | lookup model_pricing model OUTPUT input_price output_price
      ```

      ```kusto APL equivalent theme={null}
      ['ai-logs']
      | extend pricing = genai_get_pricing(model)
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="ANSI SQL users">
    In ANSI SQL, you would join with a pricing table to get model costs.

    <CodeGroup>
      ```sql SQL example theme={null}
      SELECT 
        l.*,
        p.input_price,
        p.output_price
      FROM ai_logs l
      JOIN model_pricing p ON l.model = p.model_name
      ```

      ```kusto APL equivalent theme={null}
      ['ai-logs']
      | extend pricing = genai_get_pricing(model)
      ```
    </CodeGroup>
  </Accordion>
</AccordionGroup>

## Usage

### Syntax

```kusto theme={null}
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:

```json theme={null}
{
  "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**

```kusto theme={null}
['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](https://play.axiom.co/axiom-play-qf1k/query?initForm=%7B%22apl%22%3A%22%5B%27otel-demo-genai%27%5D%20%7C%20extend%20model%20%3D%20%5B%27attributes.gen_ai.request.model%27%5D%20%7C%20extend%20pricing%20%3D%20genai_get_pricing\(model\)%20%7C%20where%20isnotnull\(pricing\)%20%7C%20summarize%20request_count%20%3D%20count\(\)%20by%20model%2C%20pricing%20%3D%20tostring\(pricing\)%20%7C%20top%203%20by%20request_count%22%7D)

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

## List of related functions

* [genai\_cost](/apl/scalar-functions/genai-functions/genai-cost): Calculates total cost for a conversation. Use this for actual cost calculation after retrieving pricing information.
* [genai\_input\_cost](/apl/scalar-functions/genai-functions/genai-input-cost): Calculates input token cost. This function uses genai\_get\_pricing internally to determine input costs.
* [genai\_output\_cost](/apl/scalar-functions/genai-functions/genai-output-cost): Calculates output token cost. This function uses genai\_get\_pricing internally to determine output costs.
* [genai\_estimate\_tokens](/apl/scalar-functions/genai-functions/genai-estimate-tokens): Estimates token count. Combine with pricing information to predict costs before making API calls.
