Skip to content

Wrong assumption when working with hosted files (HostedFileContent - MIME type) #7436

@SeRgI1982

Description

@SeRgI1982

When I wan't to use OpenAI Files API to gather file_id and later work with such hosted file, OpenAI chat client wrongly assume that hosted file is file part. I am uploading an image and when work with HostedFileContent, I am getting such error:

Invalid file data: 'file_id'. Expected a file with an application/pdf MIME type,
but got unsupported MIME type 'image/png'.

I have identified a line responsible for that:

(parts ??= []).Add(ResponseContentPart.CreateInputFilePart(fileContent.FileId));

When you take a look a few lines below (ChatRole.Tool), the HostedFileContent resolves type correctly based on MediaType.

Type = fc.HasTopLevelMediaType("image") ? "input_image" : "input_file",

Metadata

Metadata

Labels

area-aiMicrosoft.Extensions.AI libraries

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions