diff --git a/lib/ai/providers/vip98k.ts b/lib/ai/providers/vip98k.ts index ef49eacd9..8d4ed8312 100644 --- a/lib/ai/providers/vip98k.ts +++ b/lib/ai/providers/vip98k.ts @@ -1788,19 +1788,27 @@ export function buildTaskBody(params: Vip98kTaskParams, invocation: Vip98kInvoca (schema?.const === "auto" || (Array.isArray(schema?.enum) && schema.enum.includes("auto"))); }); const selectedRatio = aspectRatio || "1:1"; + const configuredSizes = + params.modelConfig.imageGenConfig?.supportedImageSizes ?? + params.modelConfig.capabilities?.supportedImageSizes; + const fixedOneK = + resolution === "1K" && + Array.isArray(configuredSizes) && + configuredSizes.length === 1 && + configuredSizes[0] === "1K"; if (!aspectRatio && automaticRatioField && hasNativeResolution && sizes?.includes(resolution)) { body[automaticRatioField] = "auto"; body.size = resolution; - } else if (ratios.includes(selectedRatio) && !(hasSeparateAspectRatio && pixels.length)) { - // Some routes express the ratio through size alone. Routes with a - // separate ratio and pixel presets can require both fields. + } else if (hasSeparateAspectRatio && fixedOneK && sizes?.includes("auto") && ratios.includes(selectedRatio)) { + // A fixed-tier route can use its explicit ratio without a second geometry + // constraint. Its published pixel presets may round the nominal ratio. + body.size = "auto"; + } else if (ratios.includes(selectedRatio)) { body.size = selectedRatio; } else if (sizes?.includes(resolution) && hasNativeAspectRatio) body.size = resolution; else if (pixels.length && (resolution || aspectRatio)) { const [rw, rh] = selectedRatio.split(":").map(Number); - const matching = pixels.filter( - ({ width, height }) => Math.abs((width * rh) / (height * rw) - 1) < 0.02, - ); + const matching = pixels.filter(size => Math.abs(size.width / size.height - rw / rh) < 0.025); if (!matching.length && sizes?.includes("auto") && hasNativeAspectRatio && hasNativeResolution) { body.size = "auto"; } else { diff --git a/tests/routes/vip98k-model-expansion.test.ts b/tests/routes/vip98k-model-expansion.test.ts index 5c2cc7df8..5faeddeee 100644 --- a/tests/routes/vip98k-model-expansion.test.ts +++ b/tests/routes/vip98k-model-expansion.test.ts @@ -56,7 +56,7 @@ test("mixed size enums retain ratio aliases when size is the ratio field", () => expect(body).toMatchObject({ size: "16:9", resolution: "2K" }); }); -test("GPT Image 2.6 uses the published pixel preset with the requested ratio", () => { +test("GPT Image 2.6 sends the selected ratio without a competing pixel size", () => { const presets = [ ["9:16", "941x1672"], ["21:9", "1920x832"], @@ -65,19 +65,21 @@ test("GPT Image 2.6 uses the published pixel preset with the requested ratio", ( ]; const ratios = presets.map(([ratio]) => ratio); const contract = invocation({ - size: { enum: [...ratios, ...presets.map(([, size]) => size)] }, + size: { enum: ["auto", ...ratios, ...presets.map(([, size]) => size)] }, aspect_ratio: { enum: ratios }, image: { type: "array", items: { type: "string" } }, quality: { enum: ["auto"] }, }, { size: "1024x1024", image: [], quality: "auto" }); const references = ["https://example.com/one.png"]; - for (const [aspectRatio, size] of presets) { + for (const aspectRatio of ratios) { const { body } = buildTaskBody({ ...params, modelId: "gpt-image-2.6", imageUrls: references, + modelConfig: { imageGenConfig: { supportedImageSizes: ["1K"] } }, imageParams: { aspectRatio, imageSize: "1K" }, }, contract); - expect(body).toMatchObject({ size, aspect_ratio: aspectRatio, image: references, quality: "auto" }); + expect(body).toMatchObject({ size: "auto", aspect_ratio: aspectRatio, image: references, quality: "auto" }); + expect(body).not.toHaveProperty("resolution"); } });