Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Create image edit

Edit an existing image given a prompt and an optional mask, following the OpenAI Images API wire format. Send the request in one of two forms:

  • multipart/form-data: upload the image bytes in image, and optionally mask.

  • application/json: reference the image in images, and optionally mask, as either a remote HTTP or HTTPS URL or an inline base64 data: URL.

The JSON form uses images (an array) where the multipart form uses image.

post
Authorizations
AuthorizationstringRequired

Please provide header value as 'Bearer ' and don't forget to add 'Bearer' HTTP Authorization Scheme before the token.

Body

Request payload for editing an existing image. Sent as multipart/form-data. The source image is given either as the binary file part image, which is the OpenAI shape, or by reference as the text field url. The mask follows the same pair, mask or mask_image, and must be given the same way the image was: an uploaded mask alongside a referenced image, or the reverse, is rejected rather than silently dropped.

Exactly one of image or url is required. Sending neither, or both, is rejected with a 400 whose message names both fields.

urlstringOptional

The image to edit, given by reference instead of uploaded: an HTTP or HTTPS URL or a base64 data URL. Accepted as an alternative to image for compatibility with earlier versions of this API. Either this or image is required, and sending both is rejected.

promptstring · min: 1Required

Text description of the desired edit.

Example: add a party hat
mask_imagestringOptional

The mask, given by reference instead of uploaded, in the same forms as url. Accepted as an alternative to mask.

modelstring · min: 1Required

ID of the model to use.

Example: black-forest-labs/FLUX.2-klein-4B
ninteger · min: 1 · max: 10Optional

Number of edited images to generate, at most 10. A larger value is rejected with a 413. A model may also limit the total pixels one request may produce. See size. When omitted, the model chooses.

sizestringOptional

Size of the generated images as WIDTHxHEIGHT in pixels, for example 1024x1024. A side smaller than 1 or larger than 8192 pixels is rejected with a 413.

Within that, the sizes served are model-specific: a model may accept only a range of sizes, round each side to a step of its own, and limit the pixels one request may produce (n times width times height). A request outside a model's limits is rejected with a 400 whose message states the limit.

When omitted, the model chooses the size.

Example: 1024x1024
output_formatstringOptional

File format of the returned image, for example png or jpeg. Distinct from response_format, which controls how the image is delivered rather than what it is encoded as. Supported formats are model-specific. An unsupported value is rejected with a 400 whose message states the supported formats.

Example: png
imagestring · binaryOptional

The image to edit, uploaded as a file part. Must be a PNG, JPEG, or WebP image of at most 10 MiB. A larger file is rejected with a 413. Either this or url is required, and sending both is rejected. Which images a model can edit (for example a minimum size or aspect ratio) is model-specific. An image outside a model's limits is rejected with a 400 whose message states the limit.

maskstring · binaryOptional

An additional image whose transparent areas indicate where to edit image. At most 10 MiB. Whether the mask must match the dimensions of image is model-specific.

response_formatstring · enumOptional

Format of the returned images. b64_json returns the image data inline and is the only format this API serves. Images are not published at a fetchable address, so OpenAI's url is rejected with a 400.

Default: b64_jsonPossible values:
Responses
200

Successful operation.

application/json
post/v1/images/edits
POST /v1/images/edits HTTP/1.1
Host: openai.inference.de-txl.ionos.com
Authorization: Bearer YOUR_SECRET_TOKEN
Content-Type: multipart/form-data
Accept: */*
Content-Length: 214

{
  "url": "text",
  "prompt": "add a party hat",
  "mask_image": "text",
  "model": "black-forest-labs/FLUX.2-klein-4B",
  "n": 1,
  "size": "1024x1024",
  "output_format": "png",
  "image": "binary",
  "mask": "binary",
  "response_format": "b64_json"
}
{
  "created": 1700000000,
  "data": [
    {
      "b64_json": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=="
    }
  ]
}

Last updated

Was this helpful?