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 inimage, and optionallymask.application/json: reference the image inimages, and optionallymask, as either a remote HTTP or HTTPS URL or an inline base64data:URL.
The JSON form uses images (an array) where the multipart form uses image.
Please provide header value as 'Bearer ' and don't forget to add 'Bearer' HTTP Authorization Scheme before the token.
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.
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.
Text description of the desired edit.
add a party hatThe mask, given by reference instead of uploaded, in the same forms as url. Accepted as an alternative to mask.
ID of the model to use.
black-forest-labs/FLUX.2-klein-4BNumber 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.
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.
1024x1024File 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.
pngThe 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.
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.
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.
b64_jsonPossible values: Successful operation.
Bad Request
The request sent to the API was malformed.
Unauthorized
The request is missing authorization information or the authorization information provided are expired.
Forbidden
The user issuing the request does not have the needed permissions.
Not Found
The requested model or endpoint does not exist. A model that exists but lacks the capability the request needs is rejected with a 400 instead.
Payload Too Large
The request exceeds a size limit. The request body is limited to 16 MiB, an inline
base64 data URI to 12 MiB decoded, and an uploaded image or mask to 10 MiB. On
/v1/chat/completions, /v1/embeddings, and /v1/rerank, a message, query, or
document is limited to 2048 content parts. Count limits, such as the number of
documents, are stated with each field. Pass large media as a remote HTTP or HTTPS URL
instead of inline base64: a URL does not count against the size limits, though it
still counts as a content part.
Unprocessable Entity
The request was well-formed but contains semantic errors.
Too Many Requests
Your contract's rate limit is exhausted. Wait the number of seconds in Retry-After
before retrying, rather than a delay of your own. The OpenAI SDKs do this
automatically. Limits are contract-specific.
Internal Server Error
The request could not be completed because of an internal error. The request was
not necessarily rejected, so a retry is safe for idempotent calls. If it persists,
quote the value of the X-Request-Id response header when contacting support.
Bad Gateway
The model could not be reached, or stopped before it finished answering. No partial answer is returned in its place, and nothing is billed for it. Retrying is reasonable. An image or video URL in the request whose host cannot be reached, times out or answers with a server error is also answered this way.
Service Overloaded (503)
Too many large requests are already being handled at once. This applies only
to a request above a size threshold, or one sent with chunked transfer
encoding. An ordinary-sized request is never refused this way. Always retry
using the Retry-After header, not a fixed delay, to avoid a synchronized
retry storm. For sustained traffic in media, keep individual requests small:
pass large media in a JSON body as a remote HTTP or HTTPS URL rather than
inline base64, and keep a file upload small, for example by sending audio in
a compressed format such as MP3 or Opus. The message gives the advice that
fits how the request was sent.
Gateway Timeout
The model did not answer within the time allowed for it. The request may
have reached the model and may even have been served, so a retry is only safe for
idempotent calls. Retrying the same request unchanged tends to time out again: the
work itself is usually what was too slow, so prefer a smaller request (fewer or
smaller images, a shorter prompt, a lower n) or a model that can serve it.
Capacity Exhausted (529)
The service is temporarily overloaded. This is a non-standard status,
matching the convention used by other LLM providers for the same
condition: capacity is exhausted, not a client error (429) and not an
outage (503). error.code distinguishes a per-user throttle
(user_overloaded) from a system-wide capacity shortage
(server_overloaded). If you check only the status, treat both
alike. Always retry using the Retry-After header, not a
fixed delay, to avoid a synchronized retry storm.
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?