GuideImage GenerationOpenai

Edit Images

OpenAI image edit endpoint guide: inpaint or extend an image with a prompt and mask, covering form-data parameters, PNG alpha requirements and a cURL example.

Given an original image and a prompt, edit or extend the image (e.g. inpainting or modifying part of the content).


📌 Basics

  • Endpoint: POST /v1/images/edits/
  • Request domain: https://anyrouter.win
  • Authentication: Bearer Token
  • Content type: multipart/form-data (Note: file uploads are involved, so Form-Data must be used)

📥 Request Parameters (Form-Data)

ParameterTypeRequiredDescription
imagefileYesThe image to edit. Must be a square PNG file under 4MB. If no mask is provided, the image itself must have transparency (an alpha channel), which is used as the mask.
promptstringYesText describing the desired result. Maximum length 1000 characters. Example: "A sea otter wearing a beret".
maskfileNoMask image. Fully transparent areas (alpha = 0) indicate where the original image should be edited/replaced. Must be a PNG under 4MB with the same dimensions as the original image.
modelstringNoModel to use, e.g. dall-e-2.
nintegerNoNumber of images to generate (1-10). Default 1.
sizestringNoResolution: 256x256, 512x512, or 1024x1024.
response_formatstringNoReturn format: url or b64_json.
userstringNoUnique identifier of the end user.

📤 Response

Status code: 200 OK

FieldTypeDescription
createdintegerCreation timestamp.
dataarrayResult list.
└─ urlstringURL of the edited image.
└─ b64_jsonstringBase64-encoded image data.

📝 Request Example (cURL)

curl https://anyrouter.win/v1/images/edits/ \
  -H "Authorization: Bearer $YOUR_API_KEY" \
  -F image="@otter.png" \
  -F mask="@mask.png" \
  -F prompt="A cute baby sea otter wearing a beret" \
  -F n=1 \
  -F size="1024x1024"

💡 Notes

  1. Image format: You must use PNG, because the editing feature relies on the alpha channel (transparency) to identify the regions that need to be repainted.
  2. How masks work:
    • If you upload a mask file, the model modifies the transparent parts of the mask.
    • If no mask is provided, the model modifies the transparent parts of the image itself.
  3. Size restriction: The uploaded image must be square (1:1).

On this page