Skip to content

fix(genkit_openai): send non-image media as OpenAI file content parts#297

Open
irangarcia wants to merge 2 commits into
genkit-ai:mainfrom
irangarcia:fix/openai-pdf-file-content-part
Open

fix(genkit_openai): send non-image media as OpenAI file content parts#297
irangarcia wants to merge 2 commits into
genkit-ai:mainfrom
irangarcia:fix/openai-pdf-file-content-part

Conversation

@irangarcia

Copy link
Copy Markdown
Contributor

The content-part converter mapped every MediaPart to an image_url part, so PDFs and other non-image documents were rejected by the OpenAI API with "Invalid MIME type. Only image types are supported."

Branch non-image data URIs to ContentPart.fileData (the OpenAI file content part). OpenAI infers the document type from the filename extension, which Genkit's Media does not carry, so synthesize one from the MIME type. Image and remote-URL handling are unchanged.

The content-part converter mapped every MediaPart to an image_url part, so PDFs and other non-image documents were rejected by the OpenAI API with "Invalid MIME type. Only image types are supported."

Branch non-image data URIs to ContentPart.fileData (the OpenAI `file` content part). OpenAI infers the document type from the filename extension, which Genkit's Media does not carry, so synthesize one from the MIME type. Image and remote-URL handling are unchanged.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the Genkit OpenAI converter to route non-image media (such as PDFs) as file content parts instead of image_url parts, synthesizing a filename based on the MIME type to prevent API rejection. Feedback suggests cleaning the MIME type string to strip parameters (e.g., ; charset=utf-8) before matching to avoid parsing failures and malformed file extensions.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread packages/genkit_openai/lib/src/converters.dart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant