Skip to content

fix(llm-providers): pass complete data URLs through image conversion - #978

Open
youlianvr wants to merge 1 commit into
CodebuffAI:mainfrom
youlianvr:fix/preview-screenshot-base64
Open

fix(llm-providers): pass complete data URLs through image conversion#978
youlianvr wants to merge 1 commit into
CodebuffAI:mainfrom
youlianvr:fix/preview-screenshot-base64

Conversation

@youlianvr

@youlianvr youlianvr commented Aug 12, 2026

Copy link
Copy Markdown

What

Screenshot tools can hand the OpenAI-compatible converter a complete data:<mime>;base64,... URL instead of raw base64. The converter in packages/llm-providers unconditionally wrapped every string value in a second data:<mime>;base64, prefix, producing payloads like:

data:image/png;base64,data:image/png;base64,iVBORw0KG...

The nested prefix injects : and , characters where providers expect base64, so requests fail with:

Invalid 'input[126].content[0].image_url'. Expected a base64-encoded data URL with an image MIME type, but got an invalid base64-encoded value.

Vision-capable models are affected because media is only attached to them — text-only models never receive an image part, so the bug hides.

Fix

Detect a leading data: prefix in string data and pass the value through untouched. Raw base64 strings, Uint8Array, ArrayBuffer, Buffer, and URL inputs behave exactly as before (existing tests unchanged).

Why here

The producing tool lives in the private client; the converter is the public chokepoint every OpenAI-compatible provider path goes through, so hardening it fixes the whole class of double-wrapped media regardless of which tool produced the data.

Testing

  • New regression test: an already-complete data URL is emitted unchanged (no double prefix).
  • bun test packages/llm-providers/ — 31 pass, 0 fail.
  • bun run typecheck (package) — clean.
  • Prettier — clean.

Fixes #977

Screenshot tools can hand the OpenAI-compatible converter a full
`data:<mime>;base64,...` URL instead of raw base64. The converter
unconditionally wrapped the value in a second `data:<mime>;base64,`
prefix, nesting the prefix inside the payload — the resulting URL
contains `:` and `,` where base64 is expected, so providers reject
the request with "invalid base64-encoded value" and vision turns
fail on models like ChatGPT-5.6 Luna.

Detect a leading `data:` prefix and pass the value through untouched;
raw base64, Uint8Array, and URL inputs behave exactly as before.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
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.

[BUG] preview_screenshot crashes the turn with "Invalid image_url" on vision-capable models

1 participant