Mirascope Frog Logo
Mirascope
DocsBlogPricingCloud
⌘K
Type to search
⌘Kto search
Escto close
mirascope
v2.0.2
1.4k
Join our
WelcomeLearnGuidesAPI Referencev1 (Legacy)
DocsGuidesAPI
Overview
Core
Calculate Cost
Llm
CallCall ResponseCall Response ChunkContextOverrideStreamTool
Mcp
Client
Retries
FallbackTenacity
Tools
# mirascope.core.costs.calculate_cost Cost calculation utilities for LLM API calls. ## <ApiType type="Function" path="core/costs/calculate_cost" symbolName="calculate_cost" /> 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. <ParametersTable parameters={[ { "name": "provider", "type_info": { "type_str": "Provider", "description": null, "kind": "simple", "doc_url": "/docs/v1/api/core/base/types#provider" }, "description": "The LLM provider (e.g., \"openai\", \"anthropic\")" }, { "name": "model", "type_info": { "type_str": "str", "description": null, "kind": "simple", "doc_url": "https://docs.python.org/3/library/stdtypes.html#str" }, "description": "The model name (e.g., \"gpt-4\", \"claude-3-opus\")" }, { "name": "metadata", "type_info": { "type_str": "CostMetadata | None", "description": null, "kind": "union", "base_type": { "type_str": "Union", "description": null, "kind": "simple", "doc_url": "https://docs.python.org/3/library/typing.html#typing.Union" }, "parameters": [ { "type_str": "CostMetadata", "description": null, "kind": "simple", "doc_url": "/docs/v1/api/core/base/types#costmetadata" }, { "type_str": "None", "description": null, "kind": "simple", "doc_url": "https://docs.python.org/3/library/constants.html#None" } ] }, "default": "None", "description": "Additional metadata required for cost calculation" } ]} /> <ReturnTable returnType={{ "type_info": { "type_str": "float | None", "description": null, "kind": "union", "base_type": { "type_str": "Union", "description": null, "kind": "simple", "doc_url": "https://docs.python.org/3/library/typing.html#typing.Union" }, "parameters": [ { "type_str": "float", "description": null, "kind": "simple", "doc_url": "https://docs.python.org/3/library/functions.html#float" }, { "type_str": "None", "description": null, "kind": "simple", "doc_url": "https://docs.python.org/3/library/constants.html#None" } ] }, "description": "The calculated cost in USD or None if unable to calculate" }} />

Provider

On this page

Provider

On this page

© 2026 Mirascope. All rights reserved.

Mirascope® is a registered trademark of Mirascope, Inc. in the U.S.

Privacy PolicyTerms of Use