From e2a4ce4dc286e1e3bf99de4c97ba370c1a189033 Mon Sep 17 00:00:00 2001 From: li2631026381-alt <243695764+li2631026381-alt@users.noreply.github.com> Date: Mon, 17 Aug 2026 13:54:19 +0800 Subject: [PATCH 1/3] fix(responses): include output text annotations --- .../transformation.py | 6 ++- ...responses_transformation_transformation.py | 49 +++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/litellm/completion_extras/litellm_responses_transformation/transformation.py b/litellm/completion_extras/litellm_responses_transformation/transformation.py index 579cf83bffa..44d9eb83608 100644 --- a/litellm/completion_extras/litellm_responses_transformation/transformation.py +++ b/litellm/completion_extras/litellm_responses_transformation/transformation.py @@ -808,7 +808,7 @@ class LiteLLMResponsesTransformationHandler(CompletionTransformationBridge): if role == "user" or role == "system" or role == "tool": return {"type": "input_text", "text": content} else: - return {"type": "output_text", "text": content} + return {"type": "output_text", "text": content, "annotations": []} def _convert_content_to_responses_format_image( self, content: "ChatCompletionImageObject", role: str @@ -903,10 +903,12 @@ class LiteLLMResponsesTransformationHandler(CompletionTransformationBridge): converted[key] = file_data[key] result.append(converted) verbose_logger.debug("Chat provider: file -> %s", converted) + elif item_type == "output_text": + result.append({"annotations": [], **item}) + verbose_logger.debug("Chat provider: passthrough -> %s", item) elif item_type in [ "input_text", "input_image", - "output_text", "refusal", "input_file", "computer_screenshot", diff --git a/tests/test_litellm/completion_extras/litellm_responses_transformation/test_completion_extras_litellm_responses_transformation_transformation.py b/tests/test_litellm/completion_extras/litellm_responses_transformation/test_completion_extras_litellm_responses_transformation_transformation.py index b8bd5c951ee..fe2d5ec88f2 100644 --- a/tests/test_litellm/completion_extras/litellm_responses_transformation/test_completion_extras_litellm_responses_transformation_transformation.py +++ b/tests/test_litellm/completion_extras/litellm_responses_transformation/test_completion_extras_litellm_responses_transformation_transformation.py @@ -18,6 +18,55 @@ from litellm.completion_extras.litellm_responses_transformation.transformation i ) +@pytest.mark.parametrize( + ("content", "expected_content"), + [ + ( + "ok", + [{"type": "output_text", "text": "ok", "annotations": []}], + ), + ( + [{"type": "text", "text": "ok"}], + [{"type": "output_text", "text": "ok", "annotations": []}], + ), + ( + [{"type": "output_text", "text": "ok"}], + [{"type": "output_text", "text": "ok", "annotations": []}], + ), + ( + [ + { + "type": "output_text", + "text": "ok", + "annotations": [{"type": "url_citation", "url": "https://example.com"}], + } + ], + [ + { + "type": "output_text", + "text": "ok", + "annotations": [{"type": "url_citation", "url": "https://example.com"}], + } + ], + ), + ], +) +def test_assistant_output_text_includes_required_annotations(content, expected_content): + handler = LiteLLMResponsesTransformationHandler() + + response, _ = handler.convert_chat_completion_messages_to_responses_api( + [{"role": "assistant", "content": content}] + ) + + assert response == [ + { + "type": "message", + "role": "assistant", + "content": expected_content, + } + ] + + def test_convert_chat_completion_messages_to_responses_api_image_input(): from litellm.completion_extras.litellm_responses_transformation.transformation import ( LiteLLMResponsesTransformationHandler, From 2647e54ada82d1b98f4adf78cb3d0d4d89acfeaf Mon Sep 17 00:00:00 2001 From: li2631026381-alt <243695764+li2631026381-alt@users.noreply.github.com> Date: Mon, 17 Aug 2026 14:00:51 +0800 Subject: [PATCH 2/3] refactor(responses): keep bridge complexity flat --- .../transformation.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/litellm/completion_extras/litellm_responses_transformation/transformation.py b/litellm/completion_extras/litellm_responses_transformation/transformation.py index 44d9eb83608..c385fc31fb7 100644 --- a/litellm/completion_extras/litellm_responses_transformation/transformation.py +++ b/litellm/completion_extras/litellm_responses_transformation/transformation.py @@ -810,6 +810,12 @@ class LiteLLMResponsesTransformationHandler(CompletionTransformationBridge): else: return {"type": "output_text", "text": content, "annotations": []} + @staticmethod + def _ensure_output_text_annotations(item: dict[str, object]) -> dict[str, object]: + if item.get("type") == "output_text": + return {"annotations": [], **item} + return item + def _convert_content_to_responses_format_image( self, content: "ChatCompletionImageObject", role: str ) -> "ResponseInputImageParam": @@ -903,19 +909,17 @@ class LiteLLMResponsesTransformationHandler(CompletionTransformationBridge): converted[key] = file_data[key] result.append(converted) verbose_logger.debug("Chat provider: file -> %s", converted) - elif item_type == "output_text": - result.append({"annotations": [], **item}) - verbose_logger.debug("Chat provider: passthrough -> %s", item) elif item_type in [ "input_text", "input_image", + "output_text", "refusal", "input_file", "computer_screenshot", "summary_text", ]: # Already in responses API format - result.append(item) + result.append(self._ensure_output_text_annotations(item)) verbose_logger.debug("Chat provider: passthrough -> %s", item) else: # Default to input_text for unknown types From b52e0526330296476a8a52998598a5893f2a3b59 Mon Sep 17 00:00:00 2001 From: li2631026381-alt <243695764+li2631026381-alt@users.noreply.github.com> Date: Mon, 17 Aug 2026 14:16:26 +0800 Subject: [PATCH 3/3] test(responses): cover passthrough content --- ..._extras_litellm_responses_transformation_transformation.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_litellm/completion_extras/litellm_responses_transformation/test_completion_extras_litellm_responses_transformation_transformation.py b/tests/test_litellm/completion_extras/litellm_responses_transformation/test_completion_extras_litellm_responses_transformation_transformation.py index fe2d5ec88f2..d00fa09a0af 100644 --- a/tests/test_litellm/completion_extras/litellm_responses_transformation/test_completion_extras_litellm_responses_transformation_transformation.py +++ b/tests/test_litellm/completion_extras/litellm_responses_transformation/test_completion_extras_litellm_responses_transformation_transformation.py @@ -29,6 +29,10 @@ from litellm.completion_extras.litellm_responses_transformation.transformation i [{"type": "text", "text": "ok"}], [{"type": "output_text", "text": "ok", "annotations": []}], ), + ( + [{"type": "input_text", "text": "ok"}], + [{"type": "input_text", "text": "ok"}], + ), ( [{"type": "output_text", "text": "ok"}], [{"type": "output_text", "text": "ok", "annotations": []}],