The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
add cost tracking for StandardBuiltInToolCostTracking
Ishaan Jaffded9a2e4817d
diff --git a/litellm/cost_calculator.py b/litellm/cost_calculator.pyindex e17a94c87ec..55736772af1 100644--- a/litellm/cost_calculator.py+++ b/litellm/cost_calculator.py@@ -9,6 +9,9 @@ from pydantic import BaseModelimport litellmimport litellm._loggingfrom 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_characterfrom 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: PLR0915optional_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: PLR0915rerank_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_costexcept 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_costexcept Exception as e: