Skip to content

fix: support image input in OpenAI Chat user messages#26825

Closed
KaguraTart wants to merge 1 commit into
anomalyco:devfrom
KaguraTart:fix/openai-chat-vision
Closed

fix: support image input in OpenAI Chat user messages#26825
KaguraTart wants to merge 1 commit into
anomalyco:devfrom
KaguraTart:fix/openai-chat-vision

Conversation

@KaguraTart
Copy link
Copy Markdown

Convert MediaPart to OpenAI image_url content block format in user messages.
Adds schema for text and image_url content blocks. Updates lowerUserMessage
to handle mixed text+media content. Adds tests for media handling.

Fixes: Custom OpenAI-compatible providers image file attachments not reaching
vision-capable models.

Convert MediaPart to OpenAI image_url content block format in user messages.
Adds schema for text and image_url content blocks. Updates lowerUserMessage
to handle mixed text+media content. Adds tests for media handling.

Fixes: Custom OpenAI-compatible providers image file attachments not reaching
vision-capable models.
Copilot AI review requested due to automatic review settings May 11, 2026 06:57
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label May 11, 2026
@github-actions
Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Related PRs Found:

  1. fix(provider): enable image support for custom OpenAI-compatible providers #21627 - "fix(provider): enable image support for custom OpenAI-compatible providers"

    • Directly related to the same issue of supporting image attachments with OpenAI-compatible providers and vision models
  2. feat(tool): Add media attachments to read tool #22258 - "feat(tool): Add media attachments to read tool"

    • Related to media/image handling in the system, though focused on the read tool rather than chat messages

These PRs may be addressing overlapping functionality related to image support in OpenAI providers. PR #21627 is particularly relevant as it specifically mentions enabling image support for custom OpenAI-compatible providers, which aligns with the current PR's fix for "Custom OpenAI-compatible providers image file attachments."

@KaguraTart KaguraTart closed this May 11, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the OpenAI Chat (/chat/completions) protocol lowering so LLM.user(...) messages containing image media are converted into OpenAI’s content: [{ type: "image_url", ... }] format, enabling vision-capable OpenAI-compatible providers to receive image attachments.

Changes:

  • Extend the OpenAI Chat request schema to allow user content as either a string or an array of typed content blocks (text / image_url).
  • Update lowerUserMessage to emit content blocks when media is present, converting MediaPart into a data:<mime>;base64,... URL.
  • Replace/expand tests to assert correct lowering for media-only, mixed text+media, and text-only user messages.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
packages/llm/src/protocols/openai-chat.ts Adds OpenAI Chat content-block schema + lowers user media parts into image_url blocks.
packages/llm/test/provider/openai-chat.test.ts Adds assertions for prepared OpenAI Chat bodies when user messages contain media and mixed content.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +206 to +210
type: "image_url" as const,
image_url: {
url: `data:${part.mediaType};base64,${mediaBytes(part)}`,
},
}
Comment on lines +220 to +222
if (hasMedia) {
const contentBlocks = message.content.map((part) => lowerUserPart(part as TextPart | MediaPart))
return { role: "user" as const, content: contentBlocks }
Comment on lines +182 to +190
it.effect("prepares user message with media as image_url content block", () =>
Effect.gen(function* () {
const error = yield* LLMClient.prepare(
const prepared = yield* LLMClient.prepare<OpenAIChat.OpenAIChatBody>(
LLM.request({
id: "req_media",
model,
messages: [LLM.user({ type: "media", mediaType: "image/png", data: "AAECAw==" })],
}),
).pipe(Effect.flip)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:compliance This means the issue will auto-close after 2 hours. needs:issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants