Fix multimodal input support for DataContent and UriContent in OpenAI clients #671
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.
Fixes the issue where agents created from OpenAI clients failed to handle multimodal inputs (text + images) due to improper content type conversion.
Problem
The
DataContentandUriContentclasses were not being properly converted to OpenAI's expected format when used with image media types. The content parsers in bothOpenAIChatClientandOpenAIResponsesClientwere falling back tocontent.model_dump(), which produced:But OpenAI's API expects image content in this format:
This caused multimodal requests to fail with validation errors about unrecognized content types.
Solution
Updated the
_openai_content_parsermethods in both OpenAI clients to:DataContentorUriContenthas an image media type usinghas_top_level_media_type("image")image_urlstructuremodel_dump()for backward compatibilityKey Changes
DataContentandUriContentwith image media typesUsage
Now users can seamlessly combine text and images in their agent interactions:
Supported Image Formats
All common image formats are supported: PNG, JPEG, GIF, WebP, SVG, BMP, TIFF, APNG, and AVIF.
Testing
Closes the multimodal input support issue and enables robust image + text interactions in the Agent Framework.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
api.openai.compython -m pytest packages/main/tests/openai/ -v --tb=short(dns block)astral.shcurl -LsSf REDACTED(dns block)If you need me to access, download, or install something from one of these locations, you can either:
This pull request was created as a result of the following prompt from Copilot chat.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.