Skip to main content

Overview

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 Signature

client.images.edit(
    image: FileTypes,
    prompt: str,
    mask: Optional[FileTypes] = None,
    model: Optional[str] = None,
    n: Optional[int] = None,
    response_format: Optional[str] = None,
    size: Optional[str] = None,
    user: Optional[str] = None,
) -> ImagesResponse

Parameters

image
file
required
The image to edit. Must be a valid PNG file, less than 4MB, and square.
prompt
string
required
A text description of the desired edits.
mask
file
An additional image whose fully transparent areas (alpha = 0) indicate where the image should be edited. Must be a valid PNG file, less than 4MB, and the same dimensions as image.
model
string
The model to use for image editing:
  • openai/dall-e-2
  • openai/gpt-image-1
n
integer
Number of images to generate (1-10). For dall-e-3, only n=1 is supported.
response_format
string
Format for returned images: url or b64_json.
size
string
Size of the generated images. Must be one of the valid sizes for the selected model.
user
string
Unique identifier for your end-user, for monitoring and abuse detection.

Response

created
integer
Unix timestamp when the images were created.
data
array
List of edited images.

Example

import dedalus_labs

client = dedalus_labs.Client(api_key="your-api-key")

with open("original.png", "rb") as image_file:
    with open("mask.png", "rb") as mask_file:
        response = client.images.edit(
            image=image_file,
            mask=mask_file,
            prompt="Add a sunset in the background",
            model="openai/dall-e-2",
            n=1,
            size="1024x1024"
        )

print(response.data[0].url)

Build docs developers (and LLMs) love