fix(completion): transform image content in tool results for Responses API #17799
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Relevant issues
Fixes #17762
Pre-Submission checklist
tests/litellm/directorymake test-unitType
🐛 Bug Fix
Changes
When using
litellm.completion()withmodel="openai/responses/...", images in tool message content were not being transformed from Chat Completion format to Responses API format.Example Request
The tool message content was being passed directly without transformation:
Chat Completion format (what user sends):
{"type": "image_url", "image_url": {"url": "data:image/png;base64,..."}}Responses API format (what OpenAI expects):
{"type": "input_image", "image_url": "data:image/png;base64,..."}OpenAI reject the request with error 400:
Fix
Transform tool message content using
_convert_content_to_responses_format()when the content is a list (multimodal content with images).Tests Added
File:
tests/test_litellm/completion_extras/litellm_responses_transformation/test_completion_extras_litellm_responses_transformation_transformation.pyAdded
test_convert_chat_completion_messages_to_responses_api_tool_result_with_image()which verifies:image_urlcontent are correctly transformedinput_image(notimage_url)image_urlis a flat string (not nested object)detailfield is preserved"