📐 fix: Accept Custom WIDTHxHEIGHT Sizes in OpenAI Image Tools (#15904)

* 📐 fix: Accept Custom WIDTHxHEIGHT Sizes in OpenAI Image Tools

* 📐 fix: Drop Local Digit Bounds From the Image Size Pattern
This commit is contained in:
Danny Avila 2026-09-14 00:13:08 -04:00 • committed by GitHub
parent 14c5e8d8cc
commit 3c39ea5191
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 43 additions and 4 deletions

View file

@ -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);
},
);
});

View file

@ -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'],