From 9fcad0382cbf5f4c4a0a701fcb820c3a99d2a0d8 Mon Sep 17 00:00:00 2001 From: soojin Date: Sat, 13 Sep 2025 22:01:45 +0900 Subject: [PATCH] fix: improve response api handling and cold storage configuration - Fix s3_path configuration in cold storage logging to use actual logger instance path - Add proper null/empty response validation in session handler to prevent processing invalid responses --- litellm/litellm_core_utils/litellm_logging.py | 13 +++++++++++-- .../session_handler.py | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.py index 2f21d280899..07cb1d8662b 100644 --- a/litellm/litellm_core_utils/litellm_logging.py +++ b/litellm/litellm_core_utils/litellm_logging.py @@ -4150,15 +4150,24 @@ class StandardLoggingPayloadSetup: from litellm.integrations.s3 import get_s3_object_key # Only generate object key if cold storage is configured - if litellm.configured_cold_storage_logger is None: + configured_cold_storage_logger = litellm.configured_cold_storage_logger + if configured_cold_storage_logger is None: return None try: # Generate file name in same format as litellm.utils.get_logging_id s3_file_name = f"time-{start_time.strftime('%H-%M-%S-%f')}_{response_id}" + # Get the actual s3_path from the configured cold storage logger instance + s3_path = "" # default value + + # Get the actual logger instance from the logger name + custom_logger = litellm.logging_callback_manager.get_active_custom_logger_for_callback_name(configured_cold_storage_logger) + if custom_logger and hasattr(custom_logger, 's3_path') and custom_logger.s3_path: + s3_path = custom_logger.s3_path + s3_object_key = get_s3_object_key( - s3_path="", # Use empty path as default + s3_path=s3_path, # Use actual s3_path from logger configuration team_alias_prefix="", # Don't split by team alias for cold storage start_time=start_time, s3_file_name=s3_file_name, diff --git a/litellm/responses/litellm_completion_transformation/session_handler.py b/litellm/responses/litellm_completion_transformation/session_handler.py index bfb996a2385..d1e009e62dd 100644 --- a/litellm/responses/litellm_completion_transformation/session_handler.py +++ b/litellm/responses/litellm_completion_transformation/session_handler.py @@ -141,7 +141,7 @@ class ResponsesSessionHandler: # Add Output messages for this Spend Log ############################################################ _response_output = spend_log.get("response", "{}") - if isinstance(_response_output, dict): + if isinstance(_response_output, dict) and _response_output and _response_output != {}: # transform `ChatCompletion Response` to `ResponsesAPIResponse` model_response = ModelResponse(**_response_output) for choice in model_response.choices: