Skip to content

Multiple images in one edit call can't declare per-image Content-Type (mixed JPEG/PNG → 400 MIME mismatch) #1388

Open

Description

@newswen

Summary

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:

MultipartBody.Part.create(name, field.filename(), field.contentType(), body)

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

ImageEditParams params = 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(
            new ByteArrayInputStream(originalJpg),     // JPEG bytes
            new ByteArrayInputStream(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.

Notes

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions