Skip to content

images().edit() rejects image with 400 “expected file but got string” #452

Closed
@danielfariati

Description

@danielfariati

Hi there!

I’m trying to call openAIClient.images().edit(...) in the Java SDK, but I keep getting: 400: Invalid type for 'image': expected one of an array of files or file, but got a string instead.

I’ve tried a few different ways to pass the image, but so far no luck. For example, here’s a minimal repro:

import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.images.ImageEditParams;
import com.openai.models.images.ImagesResponse;

import java.io.InputStream;
import java.net.URL;

public class ImageEditTest {

    public static void main(String[] args) throws Exception {
        InputStream is = new URL("https://upload.wikimedia.org/wikipedia/en/thumb/7/7d/Lenna_%28test_image%29.png/320px-Lenna_%28test_image%29.png").openStream();

        OpenAIClient client = OpenAIOkHttpClient.fromEnv();
        ImagesResponse response = client.images().edit(
            ImageEditParams.builder()
                .model("gpt-image-1")
                .prompt("Make the image black and white")
                .image(is)
                .build()
        );

        System.out.println(response);
    }
}
  1. Am I using .image(InputStream) incorrectly?
  2. Is there a bug in the SDK?
  3. If I’m doing it wrong, could you share a working Java example?

Thanks in advance for any guidance!

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