genai_input_cost
This page explains how to use the genai_input_cost function in APL.
The genai_input_cost function calculates the cost of input tokens (prompt tokens) for a GenAI API call based on the model name and number of input tokens. This helps you understand and track the cost of prompts separately from responses.
You can use this function to analyze prompt costs, optimize prompt engineering for cost efficiency, track input spending separately, or create detailed cost breakdowns.
Usage
Syntax
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | The name of the AI model (for example, 'gpt-4', 'claude-3-opus', 'gpt-3.5-turbo'). |
| input_tokens | long | Yes | The number of input tokens (prompt tokens) used in the API call. |
Returns
Returns a real number representing the cost in dollars (USD) for the input tokens based on the model's pricing.
Example
Calculate the cost of input tokens for a GenAI chat operation.
Query
Output
| total_input_cost | avg_input_cost |
|---|---|
| 45.67 | 0.0187 |
This query calculates the total and average cost of input tokens, helping you understand prompt spending patterns.
List of related functions
- genai_output_cost: Calculates output token cost. Use this alongside input costs to understand the full cost breakdown.
- genai_cost: Calculates total cost (input + output). Use this when you need combined costs.
- genai_get_pricing: Gets pricing information. Use this to understand the pricing structure behind cost calculations.
- genai_estimate_tokens: Estimates token count from text. Combine with input cost to predict prompt costs before API calls.