Conversation
…t instead of CreateInputFilePart Agent-Logs-Url: https://github.com/dotnet/extensions/sessions/42e9240d-dc02-474b-9af4-373db24ca35b Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix wrong assumption of hosted file MIME type
Fix HostedFileContent with image MIME type sent as input_file instead of input_image
Mar 30, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes OpenAI Responses “user message” content conversion so HostedFileContent with an image MIME type (e.g., image/png, image/jpeg) is sent as input_image (optionally with detail) instead of incorrectly being sent as input_file (which can be rejected by OpenAI).
Changes:
- Route
HostedFileContentwith top-level media typeimage/*throughResponseContentPart.CreateInputImagePart(...)inOpenAIResponsesChatClient. - Extend
UserMessageWithVariousContentTypes_ConvertsCorrectlyto validate hosted image files are serialized asinput_image(with and withoutdetail).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs | Adds an image-aware HostedFileContent switch case so hosted image files map to input_image rather than input_file. |
| test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIResponseClientTests.cs | Updates the verbatim request JSON + content list to assert hosted image files are serialized as input_image (including detail). |
stephentoub
approved these changes
Mar 30, 2026
jozkee
approved these changes
Mar 31, 2026
jozkee
pushed a commit
to jozkee/extensions
that referenced
this pull request
Apr 3, 2026
… of input_image (dotnet#7438) * Initial plan * Fix HostedFileContent with image MIME type to use CreateInputImagePart instead of CreateInputFilePart Agent-Logs-Url: https://github.com/dotnet/extensions/sessions/42e9240d-dc02-474b-9af4-373db24ca35b Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
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.
HostedFileContentwith image media types (e.g.image/png) was unconditionally mapped toCreateInputFilePart, causing OpenAI to reject it with: "Expected a file with an application/pdf MIME type, but got unsupported MIME type 'image/png'".The tool output path already handled this correctly via
HasTopLevelMediaType("image")— the user message path did not.Changes
OpenAIResponsesChatClient.cs: Added aHostedFileContentcase guarded byHasTopLevelMediaType("image")before the generic fallback, routing image files throughCreateInputImagePart(with detail level support)OpenAIResponseClientTests.cs: ExtendedUserMessageWithVariousContentTypes_ConvertsCorrectlyto cover hosted image files with and without detail level