From 3bf78697ae349591831225aaf604ad14bd99dc9c Mon Sep 17 00:00:00 2001 From: jiajia Date: Mon, 18 May 2026 18:42:04 +0800 Subject: [PATCH] Honor requested image aspect ratio through Popi gateway Gemini native image edits can default to the input image dimensions unless the response format also carries the requested image shape. The NewApiWG Gemini payload now sends the existing imageConfig plus responseFormat.image so Popi 16:9 selections survive image-to-image generation while preserving the prior native config path. Constraint: Gemini image edit defaults can keep the input image dimensions when output format is not explicit Rejected: Changing composer or node sizing first | the selected aspect ratio already reached the API payload in tests Confidence: medium Scope-risk: narrow Directive: Keep imageConfig and responseFormat in sync for Gemini-native NewApiWG image models Tested: npm run test:run -- src/app/api/generate/providers/__tests__/newapiwg.test.ts src/app/api/generate/__tests__/route.test.ts Tested: PROVIDER_MODE=popi NEXT_PUBLIC_PROVIDER_MODE=popi npm run build --- src/app/api/generate/__tests__/route.test.ts | 4 ++++ src/app/api/generate/providers/__tests__/newapiwg.test.ts | 3 +++ src/app/api/generate/providers/newapiwg.ts | 6 ++++++ 3 files changed, 13 insertions(+) diff --git a/src/app/api/generate/__tests__/route.test.ts b/src/app/api/generate/__tests__/route.test.ts index 4a288549..7048ae1d 100644 --- a/src/app/api/generate/__tests__/route.test.ts +++ b/src/app/api/generate/__tests__/route.test.ts @@ -1096,6 +1096,10 @@ describe("/api/generate route", () => { aspectRatio: "9:16", imageSize: "2K", }); + expect(body.generationConfig.responseFormat.image).toMatchObject({ + aspectRatio: "9:16", + imageSize: "2K", + }); }); }); diff --git a/src/app/api/generate/providers/__tests__/newapiwg.test.ts b/src/app/api/generate/providers/__tests__/newapiwg.test.ts index 96cf2cc8..8bcd9079 100644 --- a/src/app/api/generate/providers/__tests__/newapiwg.test.ts +++ b/src/app/api/generate/providers/__tests__/newapiwg.test.ts @@ -265,6 +265,9 @@ describe("NewApiWG generation payloads", () => { expect(capturedBody!.generationConfig).toMatchObject({ responseModalities: ["IMAGE"], imageConfig: { aspectRatio: "1:1", imageSize: "2K" }, + responseFormat: { + image: { aspectRatio: "1:1", imageSize: "2K" }, + }, }); }); diff --git a/src/app/api/generate/providers/newapiwg.ts b/src/app/api/generate/providers/newapiwg.ts index 81253cfc..72828c43 100644 --- a/src/app/api/generate/providers/newapiwg.ts +++ b/src/app/api/generate/providers/newapiwg.ts @@ -856,6 +856,12 @@ async function generateImageViaNewApiWGGemini( aspectRatio, imageSize, }, + responseFormat: { + image: { + aspectRatio, + imageSize, + }, + }, }, ...dynamicInputsWithoutPrompt(input), }),