fix(llm-providers): pass complete data URLs through image conversion - #978
Open
youlianvr wants to merge 1 commit into
Open
fix(llm-providers): pass complete data URLs through image conversion#978youlianvr wants to merge 1 commit into
youlianvr wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Screenshot tools can hand the OpenAI-compatible converter a complete
data:<mime>;base64,...URL instead of raw base64. The converter inpackages/llm-providersunconditionally wrapped every string value in a seconddata:<mime>;base64,prefix, producing payloads like:The nested prefix injects
:and,characters where providers expect base64, so requests fail with: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, andURLinputs 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
bun test packages/llm-providers/— 31 pass, 0 fail.bun run typecheck(package) — clean.Fixes #977