Skip to Content
ModelsGPT ImageEdit & combine images

Edit & combine images

Upload one or more images and change or merge them with a prompt.

Not writing code? See Generate images in your own tools.

POST/v1/images/editsShared parameters

Before you start

You needDetails
API keyCreate one in the OfoxAI console  and replace YOUR_OFOX_API_KEY in the code
EnvironmentcURL needs jq to decode the image; Python needs pip install openai; Node.js 18 or later, no dependencies
ImagesPut an input.png in the current directory; for combining images, add an input2.png too. PNG or JPEG, ≤ 15 MB each
TimeoutSet your client timeout to 600 seconds. High quality, large sizes or editing can take several minutes
Values used in the code
API URLhttps://api.ofox.io/v1
Model IDopenai/gpt-image-2.6-sunburstThe samples use flare; sunburst is recommended for editing
API keyReplace YOUR_OFOX_API_KEY in the code with your key
Python depspip install openai

Edit an image

Every sample below was run verbatim. The result is saved as output.png in the current directory.

Terminal
curl -s https://api.ofox.io/v1/images/edits \ -H "Authorization: Bearer YOUR_OFOX_API_KEY" \ -F "model=openai/gpt-image-2.6-flare" \ -F "image=@input.png" \ -F "prompt=Replace the background with a wooden table, keep the subject unchanged" \ -F "quality=low" \ -o response.json jq -r '.data[0].b64_json' response.json | base64 --decode > output.png

If you omit size, the model picks the output size, which may differ from the original. To keep the original size, pass it explicitly, e.g. size=1024x1024.

Writing the prompt

Say two things clearly: what to change, and what to keep.

Use caseExample prompt
Edit one imageReplace the background with a wooden tabletop and keep the subject unchanged
Combine imagesPut the subject of the first image on the background of the second image

With several images, refer to them in upload order as “the first image” and “the second image”. To change only a small part of the image, Inpainting is more reliable.

Combine several images

Send several reference images at once. Upload order is what “the first image” and “the second image” in your prompt refer to. Put input.png and input2.png in the current directory.

Terminal
# Up to 16 images per request, ≤ 15 MB each curl -s https://api.ofox.io/v1/images/edits \ -H "Authorization: Bearer YOUR_OFOX_API_KEY" \ -F "model=openai/gpt-image-2.6-flare" \ -F "image[]=@input.png" \ -F "image[]=@input2.png" \ -F "prompt=Place the subject of the first image onto the background of the second" \ -F "quality=low" \ -o response.json jq -r '.data[0].b64_json' response.json | base64 --decode > output.png

Markup editing (markup)

Key pointSupported by 2.6 and 2.5. Circling what to change on a transparent layer is more precise than describing its position in words.

Prepare a transparent PNG the same size as the original image as a markup layer, and circle, draw arrows or write on it to mark where to change; in the prompt, say what to do with the marked area. The model overlays the markup layer on the first image to understand your intent, and the markup does not appear in the output.

RequirementDetails
FormatTransparent PNG; must contain transparent pixels
DimensionsExactly the same as the first image (width and height after correcting for image orientation)
SizeThe original image and the markup layer each up to 16,777,216 pixels; markup layer file up to 50 MB
Cannot be combined withmask
BillingBilled by token like an ordinary edit. The markup layer counts as input; in our tests it added about 90 input tokens compared with no markup layer

First, generate a markup layer with Python: draw a red circle on a transparent canvas.

make_markup.py
# pip install pillow from PIL import Image, ImageDraw w, h = Image.open("input.png").size # same size as the original layer = Image.new("RGBA", (w, h), (0, 0, 0, 0)) # fully transparent canvas draw = ImageDraw.Draw(layer) draw.ellipse([w * 0.3, h * 0.3, w * 0.7, h * 0.7], outline=(255, 0, 0, 255), width=12) layer.save("markup.png")

Then submit the original image together with the markup layer:

Terminal
curl -s https://api.ofox.io/v1/images/edits \ -H "Authorization: Bearer YOUR_OFOX_API_KEY" \ -F "model=openai/gpt-image-2.6-sunburst" \ -F "image=@input.png" \ -F "markup=@markup.png" \ -F "prompt=Replace the object inside the red circle with a blue star, keep everything else unchanged" \ -F "quality=low" \ -o response.json jq -r '.data[0].b64_json' response.json | base64 --decode > output.png

How markup editing differs from inpainting: a mask uses its transparent area to define the region that may be repainted; a markup layer is a hint drawn for the model, used to point out the location and your intent.

Providers

You don’t need to pin a provider; the gateway routes requests automatically. For 2.5 and gpt-image-2, both Azure and OpenAI serve the edit endpoint; 2.6 is currently served by OpenAI only.

If you have content moderation requirements you can select a provider, but the edit endpoint only accepts the X-OfoxAI-Provider-Type header; extra_body in the form is ignored. Once a provider is selected, requests will not fall back to another provider if it is unavailable. See Selecting a provider.

Parameter values

Parameters specific to the edit endpoint. model, n, output_format and the rest work as in text to image — see Text to image · Parameter values.

Required
imagerequiredfileform

The image to edit. For several images, repeat the field as image[]; with the Python SDK, pass a list.

▸ Details

Reference images are billed as tokens too: a 1024×1024 reference image measured 1,024 input tokens, which is why editing costs more than text to image at the same size.

▶Advanced · 2markup · X-OfoxAI-Provider-TypeExpand
markupfileform· valuestransparent PNG

Supported by 2.6 and 2.5. The markup layer: same dimensions as the first image, containing transparent pixels; cannot be combined with mask. See Markup editing.

X-OfoxAI-Provider-Typestringheader· valuesazure_foundryopenai

Usually not needed — the gateway routes automatically. Use it only to pin a specific provider. 2.6 currently accepts only openai.

Upload limits

ItemLimit
Each reference image≤ 15 MB
Whole request≤ 50 MB
Number of imagesNo gateway limit; keep it to 16 or fewer
FormatPNG, JPEG

The model scales reference images to about 1024 px. Files over 5 MB only make the upload slower; they do not improve the result.

Common errors

ErrorCauseFix
Invalid image file or modeThe uploaded image is not a standard PNG or JPEGRe-export as PNG or JPEG
Invalid file 'image[0]': unsupported mimetypeThe uploaded file is not an imageUpload a PNG, JPEG or WebP image
does not support the 'input_fidelity' parameterinput_fidelity was sentRemove it; this family always processes reference images at high fidelity
moderation_blockedThe prompt or reference image was blocked by the upstream safety systemChange the prompt or reference image and try again
provider_type_unavailableThe provider you pinned manually doesn’t serve this modelRemove the X-OfoxAI-Provider-Type header
Invalid sizeThe size you passed breaks one of the four rulesSee Size
404 model_not_foundModel ID misspelled or wrong caseCopy the model ID from this page
Markup must have the same dimensions as the first imageThe markup layer and the first image differ in sizeRegenerate the markup layer at the original image’s size — see Markup editing
SVG output is not supported for image editsoutput_format: "svg" was sent to the edit endpointSVG can only be generated with the text-to-image endpoint

For other errors, see the full error table.

Official docs

OpenAI’s docs describe behavior when you call OpenAI directly. When you call through OfoxAI, the measured results in these pages take precedence. For example, you don’t need to pin a provider for editing.

Last updated on