A Practical Guide to GPT Image 2 Image Editing with URL References and Masks

When an image-editing workflow needs to preserve composition while changing only specific visual details, a plain text-to-image prompt is usually too loose; you need a repeatable edit endpoint that accepts reference images, explicit instructions, and, when necessary, a mask.
What you can do
The Ace Data Cloud OpenAI Images Edits API exposes POST https://api.acedata.cloud/openai/images/edits for editing existing images with GPT Image 2 and GPT Image 2.5 model variants. In practical terms, you can:
- Send a public image URL and describe what should change.
- Upload a local image with
multipart/form-data. - Provide multiple reference images through the
imagefield, up to 16 references for the GPT Image series. - Use a PNG
maskwith an Alpha channel when you need to constrain the editable region. - Choose URL output with
response_format=urlor base64 output withresponse_format=b64_json. - Use
callback_urlfor longer-running jobs where a synchronous request may not be ideal.
How it works
The editing contract is simple: authenticate with a Bearer API key, send an image reference or file upload, choose a supported model, and pass a prompt that explains the final image you want. The core fields are model, image, prompt, size, n, response_format, mask, and callback_url.
For URL-based editing, image can be a single URL or an array of URLs. For local files, use multipart fields such as image=@input.png. If you use a mask, both the original image and the mask must be uploaded as multipart files in the same request; do not combine a URL source image with a local mask file.
Model choices documented for this endpoint include gpt-image-2, gpt-image-2:reverse, gpt-image-2:official, gpt-image-2.5-flare, gpt-image-2.5-flare:official, gpt-image-2.5-sunburst, and gpt-image-2.5-sunburst:official. The names are worth keeping explicit in your code because they express different routing and quality/speed preferences.
Edit from an image URL
The fastest path is to start with an image URL. This is useful for build scripts, content tools, CMS integrations, and design-review bots where the source asset already lives on a CDN.
curl https://api.acedata.cloud/openai/images/edits \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"image": "https://cdn.acedata.cloud/assets/examples/gpt-image/d56455e2-e7f7-4bcd-b935-475b0a1e0948_0-18240dc44b9c.png",
"prompt": "Keep the mug, tabletop, camera angle, portrait layout, and soft shadow unchanged. Change only the mug color from white to vivid orange and the pale cream background to solid dark navy blue. No text and no logo.",
"size": "1024x1536"
}'
A successful synchronous response includes success, task_id, trace_id, created, model, data, and usage. The edited image URL appears at data[0].url. Keep the trace_id around for troubleshooting, especially if a user reports a bad edit or an API error.
Upload local files when the image is not public
If your source asset is local, private, or generated earlier in the same pipeline, use multipart/form-data. The field names remain straightforward:
curl https://api.acedata.cloud/openai/images/edits \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "model=gpt-image-2" \
-F "image=@input.png" \
-F "prompt=Replace the background with a bright modern studio"
You can pass image repeatedly for multi-reference edits. In JSON requests, the same concept is represented as an array of image URLs. This is useful when one image supplies the subject, another supplies styling, and a third provides layout or material reference.
Use masks for controlled local edits
Masks are the practical difference between “make this image better” and “change only this area.” The documented mask rules are strict and worth validating before you call the API:
maskmust be a PNG with an Alpha channel.- The mask must not exceed 4MB.
- The mask dimensions must exactly match the first
image. - Transparent pixels with Alpha value
0are editable; non-transparent pixels are retained. - Black-and-white RGB images without transparency are not valid masks.
Here is a small Python snippet that creates a transparent central rectangle in a mask:
from PIL import Image, ImageDraw
source = Image.open("input.png").convert("RGBA")
mask = Image.new("RGBA", source.size, (0, 0, 0, 255))
draw = ImageDraw.Draw(mask)
width, height = source.size
draw.rectangle(
(width // 4, height // 4, width * 3 // 4, height * 3 // 4),
fill=(0, 0, 0, 0),
)
mask.save("mask.png")
Then submit the original image and mask together:
curl https://api.acedata.cloud/openai/images/edits \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "model=gpt-image-2:official" \
-F "image=@input.png" \
-F "mask=@mask.png" \
-F "prompt=Keep the composition, lighting, and all objects outside the transparent mask unchanged. Inside the masked area, replace the empty tabletop with a small blue ceramic vase."
Canvas size, callbacks, and troubleshooting
The size field can be auto or a compliant WIDTHxHEIGHT. Width and height must be multiples of 16, the longer side must not exceed 3840, total pixels must be between 655,360 and 8,294,400, and the aspect ratio must not exceed 3:1. If size is omitted or set to auto, the model chooses a canvas based on the prompt and the first reference image.
For longer jobs, include a callback target:
{
"callback_url": "https://example.com/webhooks/images"
}
The documented asynchronous response is {"task_id":"..."}, and the final result is delivered through the callback. For common failures, check request shape first: 400 usually points to image format, image quantity, parameter combinations, size format, or mask validity; 401 means the API key or Bearer header needs attention; 429 indicates request frequency; and 504 is a sign to switch to asynchronous callbacks.
If you are building a content tool, a CMS assistant, or an internal asset pipeline, start with URL editing, add multipart uploads when files are private, and only introduce masks where deterministic local control is worth the extra validation. The full reference is available in the OpenAI Images Edits API Integration Guide.
Comments
Post a Comment