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
(perf) - only use response_cost_calculator 1 time per request. (Don't re-use the same helper twice per call ) (#7709)
Ishaan Jaffa7c803edc504
diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.pyindex d4768d8a813..7ac0174296c 100644--- a/litellm/litellm_core_utils/litellm_logging.py+++ b/litellm/litellm_core_utils/litellm_logging.py@@ -888,13 +888,9 @@ class Logging(LiteLLMLoggingBaseClass):or isinstance(result, Batch)or isinstance(result, FineTuningJob)):- ## RESPONSE COST ##- self.model_call_details["response_cost"] = (- self._response_cost_calculator(result=result)- )-## HIDDEN PARAMS ##- if hasattr(result, "_hidden_params"):+ hidden_params = getattr(result, "_hidden_params", {})+ if hidden_params:# add to metadata for loggingif self.model_call_details.get("litellm_params") is not None:self.model_call_details["litellm_params"].setdefault(@@ -913,6 +909,15 @@ class Logging(LiteLLMLoggingBaseClass):] = getattr(result, "_hidden_params", {})+ ## RESPONSE COST - Only calculate if not in hidden_params ##+ if "response_cost" in hidden_params:+ self.model_call_details["response_cost"] = hidden_params[+ "response_cost"+ ]+ else:+ self.model_call_details["response_cost"] = (+ self._response_cost_calculator(result=result)+ )## STANDARDIZED LOGGING PAYLOADself.model_call_details["standard_logging_object"] = (