Skip to content

Commit 9fcad03

Browse files
committed
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
1 parent de8cf40 commit 9fcad03

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

litellm/litellm_core_utils/litellm_logging.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4150,15 +4150,24 @@ def _generate_cold_storage_object_key(
41504150
from litellm.integrations.s3 import get_s3_object_key
41514151

41524152
# Only generate object key if cold storage is configured
4153-
if litellm.configured_cold_storage_logger is None:
4153+
configured_cold_storage_logger = litellm.configured_cold_storage_logger
4154+
if configured_cold_storage_logger is None:
41544155
return None
41554156

41564157
try:
41574158
# Generate file name in same format as litellm.utils.get_logging_id
41584159
s3_file_name = f"time-{start_time.strftime('%H-%M-%S-%f')}_{response_id}"
41594160

4161+
# Get the actual s3_path from the configured cold storage logger instance
4162+
s3_path = "" # default value
4163+
4164+
# Get the actual logger instance from the logger name
4165+
custom_logger = litellm.logging_callback_manager.get_active_custom_logger_for_callback_name(configured_cold_storage_logger)
4166+
if custom_logger and hasattr(custom_logger, 's3_path') and custom_logger.s3_path:
4167+
s3_path = custom_logger.s3_path
4168+
41604169
s3_object_key = get_s3_object_key(
4161-
s3_path="", # Use empty path as default
4170+
s3_path=s3_path, # Use actual s3_path from logger configuration
41624171
team_alias_prefix="", # Don't split by team alias for cold storage
41634172
start_time=start_time,
41644173
s3_file_name=s3_file_name,

litellm/responses/litellm_completion_transformation/session_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ async def extend_chat_completion_message_with_spend_log_payload(
141141
# Add Output messages for this Spend Log
142142
############################################################
143143
_response_output = spend_log.get("response", "{}")
144-
if isinstance(_response_output, dict):
144+
if isinstance(_response_output, dict) and _response_output and _response_output != {}:
145145
# transform `ChatCompletion Response` to `ResponsesAPIResponse`
146146
model_response = ModelResponse(**_response_output)
147147
for choice in model_response.choices:

0 commit comments

Comments
 (0)