mirascope.core.costs.calculate_cost¶
Cost calculation utilities for LLM API calls.
calculate_cost
¶
calculate_cost(
provider: Provider,
model: str,
metadata: CostMetadata | None = None,
) -> float | None
Calculate the cost for an LLM API call.
This function routes to the appropriate provider-specific cost calculation function, preserving existing behavior while providing a unified interface.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
provider |
Provider
|
The LLM provider (e.g., "openai", "anthropic") |
required |
model |
str
|
The model name (e.g., "gpt-4", "claude-3-opus") |
required |
metadata |
CostMetadata | None
|
Additional metadata required for cost calculation |
None
|
Returns:
Type | Description |
---|---|
float | None
|
The calculated cost in USD or None if unable to calculate |