[PR #11323] fix(opencode): Fixes image reading with OpenAI-compatible providers like Kimi K2.5. #13740

Closed
opened 2026-02-16 18:18:34 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/11323

State: closed
Merged: Yes


What does this PR do?

Fixes #11304.
Fixes #11306.
Fixes #11550.

Problem: When using the Read tool to read an image file, Claude works fine but OpenAI-compatible providers (Kimi, etc.) fail to see the actual image content. The model either dumps base64 data as text or hallucinates the image content.

Root cause: OpenAI-compatible Chat Completions API only supports string content in tool results. When the Read tool returns an image as an attachment, it gets JSON.stringify()'d and the model can't interpret it as an image.

Solution: For providers using @ai-sdk/openai-compatible SDK that support image input:

  • Extract media (images, PDFs) from tool results
  • Inject them as a synthetic user message after the assistant message
  • The model then sees the media as user-provided content, which is supported

How did you verify your code works?

  1. Tested with Kimi K2.5 - asked it to read /tmp/test.png (a dashboard screenshot)
  2. Before fix: Model dumped base64 or hallucinated "Hello World" text
  3. After fix: Model correctly described the dashboard UI with "Explore", "Dashboards", "Monitors" etc.
Screenshot 2026-01-31 at 1 41 41 am
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/11323 **State:** closed **Merged:** Yes --- ### What does this PR do? Fixes #11304. Fixes #11306. Fixes #11550. **Problem:** When using the Read tool to read an image file, Claude works fine but OpenAI-compatible providers (Kimi, etc.) fail to see the actual image content. The model either dumps base64 data as text or hallucinates the image content. **Root cause:** OpenAI-compatible Chat Completions API only supports string content in tool results. When the Read tool returns an image as an attachment, it gets `JSON.stringify()`'d and the model can't interpret it as an image. **Solution:** For providers using `@ai-sdk/openai-compatible` SDK that support image input: - Extract media (images, PDFs) from tool results - Inject them as a synthetic user message after the assistant message - The model then sees the media as user-provided content, which is supported ### How did you verify your code works? 1. Tested with Kimi K2.5 - asked it to read `/tmp/test.png` (a dashboard screenshot) 2. Before fix: Model dumped base64 or hallucinated "Hello World" text 3. After fix: Model correctly described the dashboard UI with "Explore", "Dashboards", "Monitors" etc. <img width="849" height="473" alt="Screenshot 2026-01-31 at 1 41 41 am" src="https://github.com/user-attachments/assets/2a15f05b-b9c9-4a66-8d99-5d8c7be67bd2" />
yindo added the pull-request label 2026-02-16 18:18:34 -05:00
yindo closed this issue 2026-02-16 18:18:34 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13740