From 61f30a8bb1fd13d34603e28f6d78fc45e9c54369 Mon Sep 17 00:00:00 2001 From: Konstantin Fickel Date: Sun, 15 Feb 2026 14:47:52 +0100 Subject: [PATCH] fix: don't pass response_format to gpt-image-* models gpt-image-* models return b64_json by default and reject the response_format parameter with a 400 error. Only pass it for DALL-E models which default to url. --- bulkgen/providers/openai_image.py | 39 +++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/bulkgen/providers/openai_image.py b/bulkgen/providers/openai_image.py index bb087ba..d028f97 100644 --- a/bulkgen/providers/openai_image.py +++ b/bulkgen/providers/openai_image.py @@ -145,7 +145,22 @@ async def _generate_new( model: str, size: _SIZE | None, ) -> ImagesResponse: - """Generate a new image from a text prompt.""" + """Generate a new image from a text prompt. + + gpt-image-* models return b64 by default and reject ``response_format``, + so we only pass it for DALL-E models. + """ + # gpt-image-* returns b64 by default; DALL-E defaults to url. + if model.startswith("gpt-image-"): + if size is not None: + return await client.images.generate( + prompt=prompt, + model=model, + n=1, + size=size, + ) + return await client.images.generate(prompt=prompt, model=model, n=1) + if size is not None: return await client.images.generate( prompt=prompt, @@ -170,10 +185,30 @@ async def _generate_edit( project_dir: Path, size: _SIZE | None, ) -> ImagesResponse: - """Generate an image using a reference image via the edits endpoint.""" + """Generate an image using a reference image via the edits endpoint. + + gpt-image-* models return b64 by default and reject ``response_format``, + so we only pass it for DALL-E models. + """ ref_path = project_dir / reference_images[0] image_bytes = ref_path.read_bytes() + if model.startswith("gpt-image-"): + if size is not None: + return await client.images.edit( + image=image_bytes, + prompt=prompt, + model=model, + n=1, + size=size, # pyright: ignore[reportArgumentType] + ) + return await client.images.edit( + image=image_bytes, + prompt=prompt, + model=model, + n=1, + ) + if size is not None: return await client.images.edit( image=image_bytes,