fix: don't pass response_format to gpt-image-* models
All checks were successful
Continuous Integration / Build Package (push) Successful in 31s
Continuous Integration / Lint, Check & Test (push) Successful in 50s

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.
This commit is contained in:
Konstantin Fickel 2026-02-15 14:47:52 +01:00
parent d1bbd95c1c
commit 61f30a8bb1
Signed by: kfickel
GPG key ID: A793722F9933C1A5

View file

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