From 3c39ea51913bcf8eef152e2093f63be1af72b7f0 Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Mon, 14 Sep 2026 00:13:08 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=90=20fix:=20Accept=20Custom=20WIDTHxH?= =?UTF-8?q?EIGHT=20Sizes=20in=20OpenAI=20Image=20Tools=20(#15904)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 📐 fix: Accept Custom WIDTHxHEIGHT Sizes in OpenAI Image Tools * 📐 fix: Drop Local Digit Bounds From the Image Size Pattern --- packages/api/src/tools/toolkits/oai.spec.ts | 36 +++++++++++++++++++++ packages/api/src/tools/toolkits/oai.ts | 11 ++++--- 2 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 packages/api/src/tools/toolkits/oai.spec.ts diff --git a/packages/api/src/tools/toolkits/oai.spec.ts b/packages/api/src/tools/toolkits/oai.spec.ts new file mode 100644 index 0000000000..e82975d422 --- /dev/null +++ b/packages/api/src/tools/toolkits/oai.spec.ts @@ -0,0 +1,36 @@ +import { oaiToolkit, IMAGE_SIZE_PATTERN } from './oai'; + +const sizeSchemas = [ + ['image_gen_oai', oaiToolkit.image_gen_oai.schema.properties?.size], + ['image_edit_oai', oaiToolkit.image_edit_oai.schema.properties?.size], +] as const; + +describe('OpenAI image toolkit size schema', () => { + const pattern = new RegExp(IMAGE_SIZE_PATTERN); + + it.each(sizeSchemas)('%s accepts any WIDTHxHEIGHT instead of a fixed list', (_name, size) => { + expect(size?.enum).toBeUndefined(); + expect(size?.pattern).toBe(IMAGE_SIZE_PATTERN); + }); + + it.each([ + 'auto', + '8x8', + '100000x100000', + '1024x1024', + '1536x1024', + '256x256', + '2048x1152', + '3840x2160', + '2160x3840', + ])('accepts %s', (value) => { + expect(pattern.test(value)).toBe(true); + }); + + it.each(['', '4K', '3840', '3840X2160', '3840 x 2160', '0x1024', '1024x0', 'auto1024x1024'])( + 'rejects %s', + (value) => { + expect(pattern.test(value)).toBe(false); + }, + ); +}); diff --git a/packages/api/src/tools/toolkits/oai.ts b/packages/api/src/tools/toolkits/oai.ts index 33d5375572..19fd2eec54 100644 --- a/packages/api/src/tools/toolkits/oai.ts +++ b/packages/api/src/tools/toolkits/oai.ts @@ -67,6 +67,9 @@ const getImageEditPromptDescription = () => { return process.env.IMAGE_EDIT_OAI_PROMPT_DESCRIPTION || DEFAULT_IMAGE_EDIT_PROMPT_DESCRIPTION; }; +/** `auto` or `WIDTHxHEIGHT`; the image API enforces which dimensions the configured model supports. */ +export const IMAGE_SIZE_PATTERN = '^(auto|[1-9][0-9]*x[1-9][0-9]*)$'; + const imageGenOaiJsonSchema: ExtendedJsonSchema = { type: 'object', properties: { @@ -88,9 +91,9 @@ const imageGenOaiJsonSchema: ExtendedJsonSchema = { }, size: { type: 'string', - enum: ['auto', '1024x1024', '1536x1024', '1024x1536'], + pattern: IMAGE_SIZE_PATTERN, description: - 'The size of the generated image. One of 1024x1024, 1536x1024 (landscape), 1024x1536 (portrait), or auto (default).', + 'The size of the generated image as WIDTHxHEIGHT in pixels, or auto (default). Common sizes: 1024x1024, 1536x1024 (landscape), 1024x1536 (portrait). Models that support custom dimensions accept others, e.g. 2048x2048 or 3840x2160; the image API rejects sizes the configured model does not support.', }, }, required: ['prompt'], @@ -123,9 +126,9 @@ Guidelines: }, size: { type: 'string', - enum: ['auto', '1024x1024', '1536x1024', '1024x1536', '256x256', '512x512'], + pattern: IMAGE_SIZE_PATTERN, description: - 'The size of the generated images. For gpt-image-1: auto (default), 1024x1024, 1536x1024, 1024x1536. For dall-e-2: 256x256, 512x512, 1024x1024.', + 'The size of the generated images as WIDTHxHEIGHT in pixels, or auto (default). Common sizes: 1024x1024, 1536x1024, 1024x1536; dall-e-2 uses 256x256, 512x512 or 1024x1024. Models that support custom dimensions accept others, e.g. 3840x2160.', }, }, required: ['image_ids', 'prompt'],