Create image edit
client.images.edit(ImageEditParamsbody , RequestOptionsoptions ?): ImagesResponse { created, background, data, 6 more } | Stream<ImageEditStreamEvent>
POST
/images/editsCreates an edited or extended image given one or more source images and a prompt. This endpoint supports GPT Image models.
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-2.6-flare",
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",
"svg_usage": {
"input_tokens": 0,
"model": "model",
"output_tokens": 0,
"reasoning_tokens": 0,
"total_tokens": 0
},
"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
}
}
}