Skip to main content
POST
/
v1
/
images
/
edits
Edit Image
curl --request POST \
  --url https://api.example.com/v1/images/edits \
  --header 'Content-Type: application/json' \
  --data '
{
  "prompt": "<string>",
  "model": "<string>",
  "n": 123,
  "size": "<string>",
  "response_format": "<string>",
  "user": "<string>"
}
'
{
  "created": 123,
  "data": [
    {
      "url": "<string>",
      "b64_json": "<string>"
    }
  ]
}
Edit images using inpainting. Supports DALL-E 2 and GPT Image 1. Upload an image and optionally a mask to indicate which areas to regenerate based on the prompt.

Method

client.images.edit(params)

Request Parameters

image
File
required
The image to edit. Must be a valid PNG file, less than 4MB, and square. If mask is not provided, image must have transparency, which will be used as the mask.
prompt
string
required
A text description of the desired image(s). The maximum length is 1000 characters.
mask
File
An additional image whose fully transparent areas (e.g. where alpha is zero) indicate where image should be edited. Must be a valid PNG file, less than 4MB, and have the same dimensions as image.
model
string
The model to use for image editing. Supported models:
  • openai/dall-e-2
  • openai/gpt-image-1
n
number
The number of images to generate. Must be between 1 and 10.Default: 1
size
string
The size of the generated images. Must be one of 256x256, 512x512, or 1024x1024.Default: 1024x1024
response_format
string
The format in which the generated images are returned:
  • url - URLs valid for 60 minutes
  • b64_json - Base64-encoded JSON
Default: url
user
string
A unique identifier representing your end-user, which can help OpenAI monitor and detect abuse.

Response

created
number
required
Unix timestamp when images were created.
data
array
required
List of generated images.

Examples

import fs from "fs";

const image = await client.images.edit({
  image: fs.createReadStream("original.png"),
  mask: fs.createReadStream("mask.png"),
  prompt: "A sunlit indoor lounge area with a pool",
  model: "openai/dall-e-2",
  n: 1,
  size: "1024x1024"
});

console.log(image.data[0].url);

Build docs developers (and LLMs) love