You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Multiple images in one edit call can't declare per-image Content-Type (mixed JPEG/PNG → 400 MIME mismatch) #1388
ImageEditParams.Image.ofInputStreams(...) wrapped in a single MultipartField<Image> sends every image as a part of one multipart field. All parts reuse the field's single filename and contentType, so there is no way to declare per-image metadata. When a request mixes formats (e.g. original JPG + reference PNG), the non-first images are declared with the wrong type and the API responds:
400: Image content does not match declared MIME type: image/jpeg
Root cause
com.openai.core.http.HttpRequestBodies.multipartFormData expands the array value of one MultipartField into multiple parts, but builds every part from the same field metadata. Decompiled from openai-java-core-4.41.0:
With contentType("image/jpeg") on the field, the request contains:
part
actual bytes
Content-Type sent
image[0]
JPEG
image/jpeg
image[1]
PNG
image/jpeg (reused from the field)
The server validates each part against its declared MIME type and rejects the mismatching part.
Reproduction
ImageEditParamsparams = ImageEditParams.builder()
.model("gpt-image-1")
.prompt("Make the product body the same color as the reference image")
.image(MultipartField.<ImageEditParams.Image>builder()
.value(ImageEditParams.Image.ofInputStreams(List.of(
newByteArrayInputStream(originalJpg), // JPEG bytesnewByteArrayInputStream(referencePng)))) // PNG bytes
.contentType("image/jpeg")
.filename("images.jpg")
.build())
.build();
client.images().edit(params);
// 400: Image content does not match declared MIME type: image/jpeg
Expected
A way to give each image in a multi-image edit its own contentType/filename, so that one multipart part per image is sent with correct headers. For example, accept a list of MultipartField<Image> (one field per image), or let each Image instance carry its own filename/content-type.
Workaround
Transcode every image to the first image's format before building the field (PNG↔JPEG). This works, but forces lossy re-encoding on callers and is easy to get wrong.
Activity