Implement computer vision solutions 3.1 Design and implement image- and video-generation solutions

A marketing team wants one new lifestyle image that combines three existing photos: a…

Study guide skill: Implement a solution that generates images from text prompts and reference media

Question B5-002

A marketing team wants one new lifestyle image that combines three existing photos: a product shot, the brand's logo, and a beach scene. They use a gpt-image-2 deployment. How should the app send the request?

Select one answer.

  • A Call the image generation API with a JSON body that contains only a text prompt describing the three photos
  • B Call the Image Edit API with a JSON body that contains the three photos as base64 strings
  • C Call the Image Edit API with all three photos as input images in a multipart/form-data request, together with a prompt that describes how to combine them ✓ Correct answer
  • D Send the product shot as the image and the logo and beach photos as mask files

Answer: C

The Image Edit API modifies existing images based on a text prompt, and it accepts several input images in one request, so the three photos can serve as reference media for the new composition. Image edit requests take multipart/form data rather than JSON. The generation API by itself works from the text prompt without input images, and a mask isn't a reference image: it marks the area of the input image to edit with fully transparent pixels.

Deep dive

How it works

Combining existing photos into a new image is an image edit, not a plain generation. The Image Edit API modifies existing images based on a text prompt. The call is like an image generation call, except you also provide input images.

Two facts decide the request format:

  1. Multiple inputs are allowed. You can provide up to 16 input images. Each must be under 50 MB and be a PNG or JPG file. So the product shot, the logo and the beach scene all go in one request as reference images.
  2. The body is multipart/form-data. The Image Edit API takes multipart form data, not JSON. In the cURL sample, each image is a form part such as image[]=@beach.png, next to fields for prompt, model, size and quality.

The prompt then explains how to combine them: for example, place the product on the beach scene and add the logo in a corner. The result comes back as base64 image data.

The other options, and when you'd use them

  • Generation API with only a text prompt: The generation call has no input images. To work from existing photos you need the edit call, which adds them.
  • Image Edit API with a JSON body of base64 strings: Wrong encoding. The Image Edit API takes multipart/form data, not JSON data.
  • Logo and beach photos as mask files: A mask isn't a reference image. It defines the area of the input image to edit using fully transparent pixels, and it must have the same dimensions as the input image.

Exam tip

Several existing photos into one new image = Image Edit API, all photos as input images, multipart/form-data. Mask = "edit only here".

References

Last reviewed:

Ready to test yourself? The quiz asks this and every other AI-103 question, with instant feedback. Practice this in a quiz →

All Computer vision questions · AI-103 study guide

Thanks for your feedback!