Add support for InputImageUrl via reflection in OpenAIResponsesChatClient#7195
Merged
stephentoub merged 8 commits intomainfrom Jan 5, 2026
Merged
Add support for InputImageUrl via reflection in OpenAIResponsesChatClient#7195stephentoub merged 8 commits intomainfrom
stephentoub merged 8 commits intomainfrom
Conversation
…ient This adds handling for the `image_url` property in `input_image` response content. Since the OpenAI SDK doesn't yet expose this property publicly, we access it via: 1. Direct property reflection (for when the property becomes public) 2. SerializedAdditionalRawData dictionary (for internal SDK storage) 3. IJsonModel serialization fallback (to extract from JSON representation) See: openai/openai-dotnet#874 Includes a unit test that validates the image URL propagates through responses. Co-authored-by: stephentoub <[email protected]>
stephentoub
reviewed
Jan 5, 2026
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs
Outdated
Show resolved
Hide resolved
Address code review feedback by using Uri.TryCreate instead of new Uri() to gracefully handle invalid URI formats. Co-authored-by: stephentoub <[email protected]>
Copilot
AI
changed the title
[WIP] Add reflection support for part.InputImageUrl property
Add support for InputImageUrl via reflection in OpenAIResponsesChatClient
Jan 5, 2026
…ImageUrl") Address code review feedback by using the simpler inline reflection pattern as originally suggested, instead of static PropertyInfo fields and fallbacks. Co-authored-by: stephentoub <[email protected]>
stephentoub
reviewed
Jan 5, 2026
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs
Outdated
Show resolved
Hide resolved
…GetType()
Cache PropertyInfo using Type.GetType("OpenAI.Responses.InternalItemContentInputImage, OpenAI")
to avoid the IL2075 trimming warning and remove the #pragma disable.
Co-authored-by: stephentoub <[email protected]>
stephentoub
reviewed
Jan 5, 2026
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs
Outdated
Show resolved
Hide resolved
Check if the image URL starts with "data:" and parse as DataContent in that case. HTTP/HTTPS URLs continue to be parsed as UriContent. Added separate tests for both cases. Co-authored-by: stephentoub <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds temporary support for the InputImageUrl property from OpenAI API responses using reflection, since the OpenAI .NET library doesn't yet expose this property publicly (pending openai/openai-dotnet#874).
Key Changes
- Added reflection-based access to the internal
ImageUrlproperty ofInternalItemContentInputImagetype - Modified
ToAIContentsmethod to handle image URLs from API responses and convert them toUriContent - Added comprehensive unit test to verify image URLs properly propagate through response parsing
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs |
Implements reflection-based property access and integrates InputImageUrl handling into the content conversion logic |
test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIResponseClientTests.cs |
Adds test case validating that input_image content with image_url is correctly parsed into UriContent |
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs
Outdated
Show resolved
Hide resolved
This was referenced Feb 4, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds temporary support for the
InputImageUrlproperty from OpenAI API responses using reflection, since the OpenAI .NET library doesn't yet expose this property publicly (pending openai/openai-dotnet#874).Changes Made
PropertyInfousingType.GetType("OpenAI.Responses.InternalItemContentInputImage, OpenAI")?.GetProperty("ImageUrl")to access the internalImageUrlproperty without triggering trimming warningsToAIContentsmethod to properly handle image URLs:UriContentdata:) are converted toDataContentUri.TryCreatefor defensive URI parsing to handle potentially malformed URLs gracefullyUriContent) and data URI (returnsDataContent) scenariosThe reflection code includes a comment citing the upstream PR so it can be replaced with the actual public property once available.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.
Microsoft Reviewers: Open in CodeFlow