Skip to main content

POST /v1/images/edits

Generates an edited version of an image based on a text prompt. You can optionally supply a mask image to restrict edits to a specific region. The request body must be sent as multipart/form-data.
This endpoint is currently supported for providers that expose an imageEdit operation, such as OpenAI (dall-e-2).

Request headers

x-portkey-provider
string
The provider to route the request to (e.g. openai). Required when not using a config.
x-portkey-api-key
string
Your provider API key.
x-portkey-config
string
A JSON config object or config ID that defines routing, fallbacks, retries, and more.
x-portkey-virtual-key
string
A virtual key ID from Portkey Cloud.

Request body

This endpoint accepts multipart/form-data. The image and mask must be uploaded as file fields, not JSON.
image
file
required
The source image to edit. Must be a valid PNG file, less than 4 MB, and square. The image must have an alpha channel (transparency) to indicate the area to edit.
prompt
string
required
A text description of the desired edit. Maximum 1000 characters.
mask
file
An optional PNG mask image that defines which areas to edit. Fully transparent areas (alpha = 0) are edited; fully opaque areas are preserved. Must be the same size as the source image.
model
string
default:"dall-e-2"
The model to use for image editing.
n
integer
default:"1"
The number of edited images to generate. Must be between 1 and 10.
size
string
default:"1024x1024"
The size of the generated images. One of 256x256, 512x512, or 1024x1024.
response_format
string
default:"url"
The format of the response. One of url or b64_json.
user
string
A unique identifier for the end user.

Response

created
integer
Unix timestamp of when the images were created.
data
object[]
An array of generated image objects.

Code examples

curl http://localhost:8787/v1/images/edits \
  -H "x-portkey-provider: openai" \
  -H "x-portkey-api-key: $OPENAI_API_KEY" \
  -F "model=dall-e-2" \
  -F "[email protected]" \
  -F "[email protected]" \
  -F "prompt=Add a sunset sky in the background" \
  -F "n=1" \
  -F "size=1024x1024"

Build docs developers (and LLMs) love