You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using OpenAIChatClient with non-OpenAI providers (such as OpenRouter with google/gemini-3-pro-image-preview), the response may contain additional fields like images that are not part of the standard OpenAI response schema. These fields are currently being lost in the _create_chat_response method.
Problem Description
Consider the following example using OpenRouter to generate images:
fromopenaiimportOpenAIclient=OpenAI(
base_url="https://openrouter.ai/api/v1",
api_key="<OPENROUTER_API_KEY>",
)
# Generate an imageresponse=client.chat.completions.create(
model="google/gemini-3-pro-image-preview",
messages=[
{
"role": "user",
"content": "Generate a beautiful sunset over mountains"
}
],
extra_body={"modalities": ["image", "text"]}
)
# The generated image will be in the assistant messagemessage=response.choices[0].messageifmessage.images:
forimageinmessage.images:
image_url=image['image_url']['url'] # Base64 data URLprint(f"Generated image: {image_url[:50]}...")
When this response passes through agent_framework/openai/_chat_client.py, the _create_chat_response method only extracts:
Text content via _parse_text_from_choice()
Tool calls via _get_tool_calls_from_chat_choice()
The images field (and potentially other provider-specific fields) is not captured and is therefore lost in the returned ChatResponse.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When using
OpenAIChatClientwith non-OpenAI providers (such as OpenRouter withgoogle/gemini-3-pro-image-preview), the response may contain additional fields likeimagesthat are not part of the standard OpenAI response schema. These fields are currently being lost in the_create_chat_responsemethod.Problem Description
Consider the following example using OpenRouter to generate images:
When this response passes through
agent_framework/openai/_chat_client.py, the_create_chat_responsemethod only extracts:_parse_text_from_choice()_get_tool_calls_from_chat_choice()The
imagesfield (and potentially other provider-specific fields) is not captured and is therefore lost in the returnedChatResponse.Relevant Code
In
_chat_client.pyline 200-224:Questions
Is there a recommended way to preserve these non-standard fields when using
OpenAIChatClientwith alternative providers?Beta Was this translation helpful? Give feedback.
All reactions