Skip to content

ToolOutputImage not recognized when using LiteLLM (Azure provider) with Agents SDK #2163

Closed

Description

@UssuGit

Please read this first

Describe the bug

When using the OpenAI Agents SDK with OpenAI models directly (model="gpt-5.1"), an agent can successfully interpret tool outputs of type ToolOutputImage.
The reasoning engine correctly handles the Base64 data URL, and the model describes the image as expected.

However, when switching the model to:

model = LitellmModel(model="azure/responses/gpt-5.1", api_key=...)

…the agent no longer recognizes the tool output as an image.

Even though the tool returns:

ToolOutputImage(image_url="data:image/jpeg;base64,...", detail="high")

LiteLLM sends an empty function_call_output to the Azure OpenAI endpoint:

'input': [{'type': 'message', 'role': 'user', 'content': [{'type': 'input_text', 'text': 'Show me the image in path/to/image.jpeg. What do you see in this image?'}]}, {'type': 'function_call', 'call_id': 'call_mprvAO3bXx8xLbA2MfDsPzKA', 'name': 'retrieve_test_image', 'arguments': '{"path":"path/to/image.jpeg"}'}, {'type': 'function_call_output', 'call_id': 'call_mprvAO3bXx8xLbA2MfDsPzKA', 'output': []}],

Because of this, the agent receives no image content and cannot describe the image.

This works correctly when not using LiteLLM.

Debug information

  • Agents SDK version: (e.g. v0.6.1)
  • Python version (e.g. Python 3.10)

Repro steps

Minimal python script that can be run to reproduce the bug:

Without LiteLLM and working:

from agents import ToolOutputImage, function_tool, Agent, Runner,
from agents.extensions.models.litellm_model import LitellmModel
from typing import Union

import json
import base64
import litellm
litellm._turn_on_debug()

@function_tool
async def retrieve_test_image(path : str) -> Union[ToolOutputImage, str]:
    b64 = base64.b64encode(open(path, "rb").read()).decode()
    return ToolOutputImage(image_url=f"data:image/jpeg;base64,{b64}", detail="high")

test_agent = Agent(
    name="Image Test Agent",
    instructions="You retrieve and describe images.",
    model="gpt-5.1",
    tools=[retrieve_test_image]
)
result = await Runner.run(test_agent, "Show me the image in path/to/image.jpeg. What do you see in this image?")

With LiteLLM and not working:

from agents import ToolOutputImage, function_tool, Agent, Runner,
from agents.extensions.models.litellm_model import LitellmModel
from typing import Union

import json
import base64
import litellm
litellm._turn_on_debug()

@function_tool
async def retrieve_test_image(path : str) -> Union[ToolOutputImage, str]:
    b64 = base64.b64encode(open(path, "rb").read()).decode()
    return ToolOutputImage(image_url=f"data:image/jpeg;base64,{b64}", detail="high")

test_agent = Agent(
    name="Image Test Agent",
    instructions="You retrieve and describe images.",
    model=LitellmModel(model="azure/responses/gpt-5.1", api_key=settings.AZURE_API_KEY),
    tools=[retrieve_test_image]
)
result = await Runner.run(test_agent, "Show me the image in path/to/image.jpeg. What do you see in this image?")

Expected behavior

LiteLLM should pass the tool output exactly as provided (the Base64 data URL) to the Azure OpenAI Responses API so the agent can interpret it as an image, just like when using OpenAI directly.

Activity

  1. added
    bug
    on Dec 9, 2025
  2. added
    question
    enhancement
    and removed
    bug
    on Dec 9, 2025
  3. seratch commented on Dec 9, 2025

    @seratch
    Member

    Thanks for sharing this. The LiteLLM adapter is available for Chat Completions compatible format at this moment, so indeed using azure responses this way may not work. We recommend directly using OpenAI client for fully-compatible Responses API models but if anyone is interested in working on the enhancement to support this use case, we're happy to have such changes (that said, if the enhancement could make the internals of the LiteLLM adapter complicated, we may want to hold off having the changes).

  4. UssuGit commented on Dec 16, 2025

    @UssuGit
    Author

    Thanks @seratch for the response!

    After debugging this further, I found the root cause is actually in chatcmpl_converter.py, not in the LiteLLM adapter itself. The issue affects multimodal tool outputs regardless of the Responses API.
    The bug is on line 547 in src/agents/models/chatcmpl_converter.py:

    elif func_output := cls.maybe_function_tool_call_output(item):
        flush_assistant_message()
        output_content = cast(
            Union[str, Iterable[ResponseInputContentWithAudioParam]], func_output["output"]
        )
        msg: ChatCompletionToolMessageParam = {
            "role": "tool",
            "tool_call_id": func_output["call_id"],
            "content": cls.extract_text_content(output_content),  # ← BUG HERE
        }
        result.append(msg)
    

    The problem is that extract_text_content() only keeps text content and drops everything else (images, audio, files):

    def extract_text_content(cls, content):
        ...
        for c in all_content:
            if c.get("type") == "text":  # Only text - images are dropped!
                out.append(...)
        return out
    

    Meanwhile, extract_all_content() (which already exists in the same file) properly handles images by converting input_image → image_url format.
    The fix is a one-line change:

    - "content": cls.extract_text_content(output_content),
    + "content": cls.extract_all_content(output_content),
    

    This wouldn't add any complexity to the LiteLLM adapter - it's fixing the Converter to properly handle multimodal tool outputs that the SDK already supports for user messages.

    I've tested this fix locally and confirmed it works, now with a similar example I've opened the issue with i can see the output being properly sent:

    POST Request Sent from LiteLLM:
    curl -X POST \
    https://....azure.com/openai/v1/responses?api-version=preview \
    -H 'api-key: ****' \
    -d '{'model': 'gpt-5.1', 'input': [{'type': 'message', 'role': 'user', 'content': [{'type': 'input_text', 'text': 'Please retrieve and show me the image with ID 30c3937c-2ff7-435b-93ba-3e09ac4d7a20 from document af0bb7c1-aee5-4ad5-a261-7472460f5019. What do you see in this image?'}]}, {'type': 'function_call', 'call_id': 'call_oc3lhxhAXhImmdeUYGOa9G23', 'name': 'retrieve_test_image', 'arguments': '{"document_id":"af0bb7c1-aee5-4ad5-a261-7472460f5019","image_id":"30c3937c-2ff7-435b-93ba-3e09ac4d7a20"}'}, {'type': 'function_call_output', 'call_id': 'call_oc3lhxhAXhImmdeUYGOa9G23', 'output': [{'image_url': 'data:image/jpeg;base64,/9j...KAP//Z', 'detail': 'high', 'type': 'input_image'}]}], ...
    

    Would you be open to a PR with this change? Happy to submit one.

  5. added this to the 0.7.x milestone on Dec 22, 2025
  6. seratch commented on Dec 22, 2025

    @seratch
    Member

    @UssuGit Thanks for taking time for investigating this! @ihower submitted a pull request that aims to resolve this. If you help the PR, it'd be appreciated!

  7. added a commit that references this issue on Dec 23, 2025
    ba55bbd
  8. spacegpu commented on Jan 4, 2026

    @spacegpu

    Hi. does ToolOutputImage work with gemini models or is it restricted to only openai models as of now

  9. ihower commented on Jan 4, 2026

    @ihower
    Contributor

    @Anurag-gg I added support for non-OpenAI models (via LiteLLM) in the PR related to this issue (#2214 ), but it is not released yet.

    In general, ToolOutputImage is not limited to OpenAI models. I tested it with anthropic/claude-sonnet-4-5-20250929, and it works.

    However, there are a few requirements:

    1. The model provider must support images in function or tool outputs. For example, Gemini 2.5 Pro does not support returning images from function calling.
    2. Gemini 3 does support this, but the OpenAI Agents SDK does not support Gemini 3 yet. This will be handled in my PR: Gemini 3 Pro support and cross-model conversation compatibility #2158
    3. LiteLLM must also support this. The fix was just merged here: Fix Gemini 3 imgs in tool response BerriAI/litellm#18190

    So this can work with non-OpenAI models, but the provider, the Agents SDK, and LiteLLM all need to support it.

  10. modified the milestones: 0.7.x, 0.6.x on Jan 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementfeature:extensionsquestion

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions