From ded9a2e4817d8b0ae7ab5b9458b7e11d42e07695 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sat, 22 Mar 2025 16:01:12 -0700 Subject: [PATCH] add cost tracking for StandardBuiltInToolCostTracking --- litellm/cost_calculator.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/litellm/cost_calculator.py b/litellm/cost_calculator.py index e17a94c87ec..55736772af1 100644 --- a/litellm/cost_calculator.py +++ b/litellm/cost_calculator.py @@ -9,6 +9,9 @@ from pydantic import BaseModel import litellm import litellm._logging from litellm import verbose_logger +from litellm.litellm_core_utils.llm_cost_calc.tool_call_cost_tracking import ( + StandardBuiltInToolCostTracking, +) from litellm.litellm_core_utils.llm_cost_calc.utils import _generic_cost_per_character from litellm.llms.anthropic.cost_calculation import ( cost_per_token as anthropic_cost_per_token, @@ -57,6 +60,7 @@ from litellm.types.utils import ( LlmProvidersSet, ModelInfo, PassthroughCallTypes, + StandardBuiltInToolsParams, Usage, ) from litellm.utils import ( @@ -524,6 +528,7 @@ def completion_cost( # noqa: PLR0915 optional_params: Optional[dict] = None, custom_pricing: Optional[bool] = None, base_model: Optional[str] = None, + standard_built_in_tools_params: Optional[StandardBuiltInToolsParams] = None, ) -> float: """ Calculate the cost of a given completion call fot GPT-3.5-turbo, llama2, any litellm supported llm. @@ -802,6 +807,12 @@ def completion_cost( # noqa: PLR0915 rerank_billed_units=rerank_billed_units, ) _final_cost = prompt_tokens_cost_usd_dollar + completion_tokens_cost_usd_dollar + _final_cost += StandardBuiltInToolCostTracking.get_cost_for_built_in_tools( + model=model, + response_object=completion_response, + standard_built_in_tools_params=standard_built_in_tools_params, + custom_llm_provider=custom_llm_provider, + ) return _final_cost except Exception as e: @@ -861,6 +872,7 @@ def response_cost_calculator( base_model: Optional[str] = None, custom_pricing: Optional[bool] = None, prompt: str = "", + standard_built_in_tools_params: Optional[StandardBuiltInToolsParams] = None, ) -> float: """ Returns @@ -890,6 +902,7 @@ def response_cost_calculator( custom_pricing=custom_pricing, base_model=base_model, prompt=prompt, + standard_built_in_tools_params=standard_built_in_tools_params, ) return response_cost except Exception as e: