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
This commit is contained in:
soojin 2025-09-13 22:01:45 +09:00
parent de8cf40ffa
commit 9fcad0382c
2 changed files with 12 additions and 3 deletions

View file

@ -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,

View file

@ -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: