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)
| Parameter | Type | Required | Description |
|---|---|---|---|
| image | file | Yes | The 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. |
| prompt | string | Yes | Text describing the desired result. Maximum length 1000 characters. Example: "A sea otter wearing a beret". |
| mask | file | No | Mask 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. |
| model | string | No | Model to use, e.g. dall-e-2. |
| n | integer | No | Number of images to generate (1-10). Default 1. |
| size | string | No | Resolution: 256x256, 512x512, or 1024x1024. |
| response_format | string | No | Return format: url or b64_json. |
| user | string | No | Unique identifier of the end user. |
📤 Response
Status code: 200 OK
| Field | Type | Description |
|---|---|---|
| created | integer | Creation timestamp. |
| data | array | Result list. |
| └─ url | string | URL of the edited image. |
| └─ b64_json | string | Base64-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
- 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.
- How masks work:
- If you upload a
maskfile, the model modifies the transparent parts of themask. - If no
maskis provided, the model modifies the transparent parts of theimageitself.
- If you upload a
- Size restriction: The uploaded image must be square (1:1).
OpenAI Chat Format
Use the OpenAI Chat Completions format to trigger Gemini image generation, with extra_body config for aspect ratio and size, and tips for parsing Base64 images.
Image Generation
OpenAI image generation API reference: create images from prompts with dall-e-3 or gpt-image models, covering size, background, quality and response format.