Skip to content

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]

refactor: make variable

Yuta Saito6ca9282857a5
diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.py
index e0a799d8e5c..45eceea9fb1 100644
--- a/litellm/litellm_core_utils/litellm_logging.py
+++ b/litellm/litellm_core_utils/litellm_logging.py
@@ -1853,6 +1853,13 @@ class Logging(LiteLLMLoggingBaseClass):
cache_hit=cache_hit,
standard_logging_object=kwargs.get("standard_logging_object", None),
)
+ litellm_params = self.model_call_details.get("litellm_params", {})
+ is_async_logging_request = (
+ litellm_params.get("acompletion", False) is not True
+ and litellm_params.get("aembedding", False) is not True
+ and litellm_params.get("aimage_generation", False) is not True
+ and litellm_params.get("atranscription", False) is not True
+ )
try:
## BUILD COMPLETE STREAMED RESPONSE
complete_streaming_response: Optional[
@@ -1915,7 +1922,6 @@ class Logging(LiteLLMLoggingBaseClass):
self.has_run_logging(event_type="sync_success")
for callback in callbacks:
try:
- litellm_params = self.model_call_details.get("litellm_params", {})
should_run = self.should_run_callback(
callback=callback,
litellm_params=litellm_params,
@@ -2185,22 +2191,7 @@ class Logging(LiteLLMLoggingBaseClass):
if (
callback == "openmeter"
- and self.model_call_details.get("litellm_params", {}).get(
- "acompletion", False
- )
- is not True
- and self.model_call_details.get("litellm_params", {}).get(
- "aembedding", False
- )
- is not True
- and self.model_call_details.get("litellm_params", {}).get(
- "aimage_generation", False
- )
- is not True
- and self.model_call_details.get("litellm_params", {}).get(
- "atranscription", False
- )
- is not True
+ and is_async_logging_request
):
global openMeterLogger
if openMeterLogger is None:
@@ -2229,22 +2220,7 @@ class Logging(LiteLLMLoggingBaseClass):
)
if (
isinstance(callback, CustomLogger)
- and self.model_call_details.get("litellm_params", {}).get(
- "acompletion", False
- )
- is not True
- and self.model_call_details.get("litellm_params", {}).get(
- "aembedding", False
- )
- is not True
- and self.model_call_details.get("litellm_params", {}).get(
- "aimage_generation", False
- )
- is not True
- and self.model_call_details.get("litellm_params", {}).get(
- "atranscription", False
- )
- is not True
+ and is_async_logging_request
and self.call_type
!= CallTypes.pass_through.value # pass-through endpoints call async_log_success_event
): # custom logger class
@@ -2272,22 +2248,7 @@ class Logging(LiteLLMLoggingBaseClass):
)
if (
callable(callback) is True
- and self.model_call_details.get("litellm_params", {}).get(
- "acompletion", False
- )
- is not True
- and self.model_call_details.get("litellm_params", {}).get(
- "aembedding", False
- )
- is not True
- and self.model_call_details.get("litellm_params", {}).get(
- "aimage_generation", False
- )
- is not True
- and self.model_call_details.get("litellm_params", {}).get(
- "atranscription", False
- )
- is not True
+ and is_async_logging_request
and customLogger is not None
): # custom logger functions
print_verbose(
@@ -2737,6 +2698,11 @@ class Logging(LiteLLMLoggingBaseClass):
event_type="sync_failure"
): # prevent double logging
return
+ litellm_params = self.model_call_details.get("litellm_params", {})
+ is_async_logging_request = (
+ litellm_params.get("acompletion", False) is not True
+ and litellm_params.get("aembedding", False) is not True
+ )
try:
start_time, end_time = self._failure_handler_helper_fn(
exception=exception,
@@ -2762,7 +2728,6 @@ class Logging(LiteLLMLoggingBaseClass):
self.has_run_logging(event_type="sync_failure")
for callback in callbacks:
try:
- litellm_params = self.model_call_details.get("litellm_params", {})
should_run = self.should_run_callback(
callback=callback,
litellm_params=litellm_params,
@@ -2830,14 +2795,7 @@ class Logging(LiteLLMLoggingBaseClass):
)
if (
isinstance(callback, CustomLogger)
- and self.model_call_details.get("litellm_params", {}).get(
- "acompletion", False
- )
- is not True
- and self.model_call_details.get("litellm_params", {}).get(
- "aembedding", False
- )
- is not True
+ and is_async_logging_request
): # custom logger class
callback.log_failure_event(
start_time=start_time,