MirascopeLilypad

mirascope.core.costs.calculate_cost

Cost calculation utilities for LLM API calls.

Function calculate_cost

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

NameTypeDescription
providerProviderThe LLM provider (e.g., "openai", "anthropic")
modelstrThe model name (e.g., "gpt-4", "claude-3-opus")
metadata= NoneCostMetadata | NoneAdditional metadata required for cost calculation

Returns

TypeDescription
float | NoneThe calculated cost in USD or None if unable to calculate