Repository navigation
fix(ai): send OpenRouter image edits as input references - #60067
Merged
Merged
Conversation
rekram1-node
force-pushed
the
openrouter-image-edits
branch
from
October 29, 2026 02:21
e8ba722 to
b1d7692
Compare
rekram1-node
enabled auto-merge (squash)
October 29, 2026 02:21
1 task done
1 task
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.
Problem
Image edits through OpenRouter never worked. OpenRouter image models use the OpenAI images protocol, and when a request has input
imagesthat protocol posts multipart to/images/edits. OpenRouter has no such endpoint, so every edit came back as HTTP 404 for every model.Just changing the path isn't enough either. OpenRouter's image API (
POST /api/v1/images, alias/images/generations) is JSON only and reads input images frominput_references: [{ type: "image_url", image_url: { url } }]. If you send OpenAI'simagesfield instead, it silently ignores it and you get an unrelated text-to-image redraw.Change
I added an
imageInputoption toOpenAIImages.model, next to thesizinghook from #59927. It defaults to"edits", so OpenAI, Azure, Vercel and the other hosts behave exactly as before. OpenRouter passes"references":A request without images sends the same body as before. Response parsing didn't need changes, since OpenRouter returns OpenAI-style
data[].b64_json.This is stacked on #59927 (
image-sizing-fixes) because both touch the same lines inopenai-images.tsandopenrouter.ts. Once that merges this retargets todevwith only its own commit.Out of scope
Image.streamthrough OpenRouter. Its stream events carrymedia_typebut nooutput_format, and the protocol currently requiresoutput_formaton partial and completed events, so streaming there fails to decode. That's a separate fix.GET /api/v1/images/modelslistsinput_references{min, max}per model (some take 0). I'm leaving the count check to OpenRouter./v1/images/edits, so I left them alone.Verification
POST /api/v1/images/editsreturns 404./api/v1/images/modelslistsinput_referencesfor nearly every model and nomaskparameter anywhere.openrouter-images/edits-an-image-through-input-referenceswithopenai/gpt-image-1-mini(about $0.002). The black circle fixture came back as the same circle in green, so it's a real edit.test/image.test.ts: no images keeps the plain body, bytes and URLs becomeinput_referenceson/images/generationsas JSON, and a mask fails withUnsupportedOperationbefore any request. These and the recorded test fail without the fix.packages/ai:bun typecheck,bun run typecheck:tsc,bun test(1979 pass). Root:bun run check.Visual