diff --git a/AGENTS.md b/AGENTS.md index e969a51..a3b2d63 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -53,7 +53,10 @@ Three files do everything: - Upstream dispatch: - `referenceImages` present → `POST {baseURL}/images/edits` as `multipart/form-data` (blobs decoded from data URLs via - `decodeDataUrl` → `Uint8Array`). + `decodeDataUrl` → `Uint8Array`). Single reference uses + field name `image`; **two or more references use `image[]`** to + match OpenAI's documented array syntax — strict gateways reject + repeated `image` parts with a `duplicate_parameter` 400. - Otherwise → `POST {baseURL}/images/generations` as JSON. - Always sends `stream: true, partial_images: 2` first. On a 400 that mentions `stream` or `partial_images` (see diff --git a/index.ts b/index.ts index c384f60..7750285 100644 --- a/index.ts +++ b/index.ts @@ -49,6 +49,7 @@ async function callUpstream(args: { form.append("stream", "true"); form.append("partial_images", "2"); } + const imageField = referenceImages.length > 1 ? "image[]" : "image"; for (let i = 0; i < referenceImages.length; i++) { const dataUrl = referenceImages[i]; if (!dataUrl) continue; @@ -56,7 +57,7 @@ async function callUpstream(args: { if (!decoded) continue; const ext = decoded.mime.split("/")[1] ?? "png"; form.append( - "image", + imageField, new Blob([decoded.bytes], { type: decoded.mime }), `ref-${i}.${ext}`, );