Skip to content
For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to the page URL.
Primary navigation

Create image edit

client.images.edit(body, options?): ImagesResponse { created, background, data, 5 more } | Stream<ImageEditStreamEvent>
POST
/images/edits

Creates an edited or extended image given one or more source images and a prompt. This endpoint supports GPT Image models.

Parameters
ImageEditParams = ImageEditParamsNonStreaming { stream } | ImageEditParamsStreaming { stream }
ImageEditParamsBase { image, prompt, background, 13 more }
ImageEditParamsNonStreaming extends ImageEditParamsBase { image, prompt, background, 13 more } { stream }
ImageEditParamsStreaming extends ImageEditParamsBase { image, prompt, background, 13 more } { stream }
Returns
ImagesResponse { created, background, data, 5 more }

The response from the image generation endpoint.

ImageEditStreamEvent = ImageEditPartialImageEvent { b64_json, background, created_at, 5 more } | ImageEditCompletedEvent { b64_json, background, created_at, 6 more }

Emitted when a partial image is available during image editing streaming.

Create image edit

import fs from "fs";
import OpenAI, { toFile } from "openai";

const client = new OpenAI();

const imageFiles = [
    "bath-bomb.png",
    "body-lotion.png",
    "incense-kit.png",
    "soap.png",
];

const images = await Promise.all(
    imageFiles.map(async (file) =>
        await toFile(fs.createReadStream(file), null, {
            type: "image/png",
        })
    ),
);

const rsp = await client.images.edit({
    model: "gpt-image-1.5",
    image: images,
    prompt: "Create a lovely gift basket with these four items in it",
});

// Save the image to a file
const image_base64 = rsp.data[0].b64_json;
const image_bytes = Buffer.from(image_base64, "base64");
fs.writeFileSync("basket.png", image_bytes);
Returns Examples
200 example
{
  "created": 0,
  "background": "transparent",
  "data": [
    {
      "b64_json": "b64_json",
      "revised_prompt": "revised_prompt",
      "url": "https://example.com"
    }
  ],
  "output_format": "png",
  "quality": "low",
  "safety_identifier": "safety_identifier",
  "size": "1024x1024",
  "usage": {
    "input_tokens": 0,
    "input_tokens_details": {
      "image_tokens": 0,
      "text_tokens": 0
    },
    "output_tokens": 0,
    "total_tokens": 0,
    "output_tokens_details": {
      "image_tokens": 0,
      "text_tokens": 0
    }
  }
}