From b510628bc2e73870f476431d8e469ef546555214 Mon Sep 17 00:00:00 2001 From: zhanghao Date: Fri, 10 Apr 2026 13:58:54 +0800 Subject: [PATCH] fix(anthropic-adapter): preserve image blocks in tool results during format conversion When converting Anthropic /v1/messages to OpenAI /v1/chat/completions format, single-image tool results had their image data stored as a plain URL string in ChatCompletionToolMessage.content, instead of a structured ChatCompletionImageObject list. This caused downstream models (e.g. vLLM) to treat the base64 data URI as plain text, making image recognition fail. The multi-item tool result path already handled this correctly by creating a ChatCompletionImageObject. This fix applies the same pattern to the single-item case. --- .../experimental_pass_through/adapters/transformation.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py b/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py index ed49943b7fe..50f69eaa992 100644 --- a/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py +++ b/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py @@ -480,7 +480,12 @@ class LiteLLMAnthropicMessagesAdapter: tool_call_id=content.get( "tool_use_id", "" ), - content=openai_image_url, + content=[ChatCompletionImageObject( + type="image_url", + image_url=ChatCompletionImageUrlObject( + url=openai_image_url + ), + )], ) self._add_cache_control_if_applicable( content, tool_result, model