diff --git a/litellm/llms/chatgpt/responses/transformation.py b/litellm/llms/chatgpt/responses/transformation.py index 66acd933416..6aae2c48b58 100644 --- a/litellm/llms/chatgpt/responses/transformation.py +++ b/litellm/llms/chatgpt/responses/transformation.py @@ -134,6 +134,7 @@ class ChatGPTResponsesAPIConfig(OpenAIResponsesAPIConfig): completed_response = None error_message = None + collected_output_items: list = [] for chunk in body_text.splitlines(): stripped_chunk = CustomStreamWrapper._strip_sse_data_from_chunk(chunk) if not stripped_chunk: @@ -150,10 +151,21 @@ class ChatGPTResponsesAPIConfig(OpenAIResponsesAPIConfig): if not isinstance(parsed_chunk, dict): continue event_type = parsed_chunk.get("type") + if event_type == ResponsesAPIStreamEvents.OUTPUT_ITEM_DONE: + item = parsed_chunk.get("item") + if isinstance(item, dict): + collected_output_items.append(item) + continue if event_type == ResponsesAPIStreamEvents.RESPONSE_COMPLETED: response_payload = parsed_chunk.get("response") if isinstance(response_payload, dict): response_payload = dict(response_payload) + # ChatGPT backend leaves response.output empty on the final + # `response.completed` event and emits items via earlier + # `response.output_item.done` events; reassemble here so + # non-streaming clients receive a populated output array. + if not response_payload.get("output") and collected_output_items: + response_payload["output"] = collected_output_items if "created_at" in response_payload: response_payload["created_at"] = _safe_convert_created_field( response_payload["created_at"]