Skip to main content

Endpoint

Creates an edited or extended version of an existing image based on a prompt.

Request

Headers

string
required
Must be multipart/form-data
string
required
The AI provider to use (e.g., openai)
string
required
Your API key for the specified provider

Form Parameters

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.
string
required
A text description of the desired edits. Maximum length is 1000 characters.
file
An additional image whose fully transparent areas indicate where the original image should be edited. Must be a PNG file, less than 4MB, and have the same dimensions as the original image.
string
The model to use for image editing. Currently only dall-e-2 is supported.
integer
default:1
Number of edited images to generate (1-10)
string
default:"1024x1024"
Size of the generated images: 256x256, 512x512, or 1024x1024
string
default:"url"
Format of the response: url or b64_json
string
Unique identifier for the end-user

Response

integer
Unix timestamp of when the edited image was created
array
Array of edited images
string
URL of the edited image (when response_format is url)
string
Base64-encoded image data (when response_format is b64_json)

Examples

Basic Image Edit

Response

Python SDK

JavaScript SDK

Using a Mask

Python with Mask

Download Edited Image

Base64 Response

Generate Multiple Variations

Creating Masks

Masks are PNG images where:
  • Transparent pixels (alpha = 0) indicate areas to edit
  • Opaque pixels (alpha = 255) indicate areas to keep unchanged

Creating a Mask in Python (PIL)

Image Requirements

  1. Format: Must be PNG with RGBA support
  2. Size: Less than 4MB
  3. Dimensions: Must be square (same width and height)
  4. Supported Sizes: 256x256, 512x512, or 1024x1024
  5. Transparency: If no mask is provided, the image must have transparent areas

Tips for Better Edits

  1. Clear Prompts: Be specific about what you want to change
  2. Use Masks: For precise control over edit regions
  3. Quality Images: Start with high-quality, clear images
  4. Appropriate Size: Use larger sizes (1024x1024) for better detail
  5. Generate Multiple: Use n > 1 to get variations

Common Use Cases

  • Object Replacement: Replace objects in images
  • Background Changes: Change backgrounds while keeping subjects
  • Style Transfer: Apply different styles to image regions
  • Inpainting: Fill in missing or unwanted parts of images
  • Enhancement: Add details or elements to existing images