OpenAI image editing service allows you to input any number of images and instructions, outputting the modified images. Currently, the API supportsDocumentation Index
Fetch the complete documentation index at: https://docs.xhuoapi.ai/llms.txt
Use this file to discover all available pages before exploring further.
dall-e-2, gpt-image-1, the latest gpt-image-2, as well as the nano-banana / nano-banana-2 / nano-banana-pro series models accessed through the same interface.
This document mainly introduces the usage process of the OpenAI Images Edits API, enabling easy use of the official OpenAI image editing features.
Application Process
To use the OpenAI Images Edits API, first visit the OpenAI Images Edits API page and click the “Acquire” button to obtain the credentials required for requests:
If you are not logged in or registered, you will be automatically redirected to the login page to register and log in. After logging in or registering, you will be automatically returned to the current page.
A free quota is granted upon first application, allowing free use of this API.
GPT-Image-2 Model
gpt-image-2 shows significant improvements over gpt-image-1 in image editing scenarios:
- More stable structure preservation: Changing skins, colors, or backgrounds almost never disrupts the original layout and composition.
- More accurate text retention: Text in infographics, posters, menus, etc., remains clear and readable after editing.
- Supports direct URL input: Besides traditional
multipart/form-datafile uploads,gpt-image-2also supports passing image URLs via JSON, eliminating the need to download images locally, which is ideal for server-side pipeline integration. - Supports high-resolution redraw: You can input a 1K original image and request 2K / 4K output via the
sizeparameter; the model will simultaneously perform upscaling during editing.
Supported size Values and Billing Tiers
The editing API’s constraints on size are identical to the generation API — gpt-image-2 only accepts size values of auto, empty, or in the WIDTHxHEIGHT format; any other format returns a 400 error. Billing is divided into two tiers, unrelated to the original image resolution, only based on the requested size value:
- 1K Standard Price: Any 1K recommended size from the table below, or common upstream 1K aliases (
1254x1254,1672x941,941x1672). - Other Tiers (1.5×): Includes the recommended 2K / 4K presets below, as well as any custom
WIDTHxHEIGHTyou provide.
| Aspect Ratio | 1K (Standard Price) | 2K Recommended (×1.5) | 4K Recommended (×1.5) |
|---|---|---|---|
| 1:1 | 1024x1024 | 2048x2048 | 2880x2880 |
| 4:3 | 1536x1024 | 2048x1536 | 3264x2448 |
| 3:4 | 1024x1536 | 1536x2048 | 2448x3264 |
| 16:9 | 1792x1024 | 2048x1152 | 3840x2160 |
| 9:16 | 1024x1792 | 1152x2048 | 2160x3840 |
For example: if the original image is1024x1024andsizeis set to2048x2048, the model will redraw and output a 2K image according to the editing instructions, billed at the “other” tier; ifsizeis3840x2160, it outputs a 4K landscape image, also billed at the “other” tier; ifsizeisautoor omitted, billing is at the 1K standard price.
About theBelow are two real examples from different perspectives showcasing the editing capabilities ofnparameter Thegpt-image-2editing API currently does not supportn > 1: this parameter is silently ignored. Whether you passn=1orn=10, only one image is returned per request and only one image is billed. If you need multiple candidate edited images at once, please make multiple concurrent requests yourself. This limitation also applies togpt-image-1/gpt-image-1.5and thenano-banana/nano-banana-2/nano-banana-proseries.dall-e-2is currently the only editing model that natively supportsn > 1.
gpt-image-2.
Method 1: JSON + Image URL (Recommended)
Send the request directly asapplication/json, with the image field containing an image URL. The model will fetch the image and edit it according to the prompt.
For example, the original image below is a science infographic generated by gpt-image-2:


Tip: Theimagefield also supports passing an array, e.g.,"image": ["url1", "url2", "url3"], with up to 16 reference images simultaneously, allowing the model to consider multiple images for editing.
Method 2: JSON + Multiple Reference Images
gpt-image-2 supports referencing multiple images simultaneously to generate the final result, for example, combining multiple product photos into a single gift basket:
Scenario Example: Style Change + Structure Preservation
Here is another example, replacing a wooden bookshelf with a modern floating shelf while strictly preserving the number and arrangement of books on each shelf. Original image (wooden bookshelf generated bygpt-image-2):

task_id: e9544dba-727e-44a2-81e1-223d49869380):

Method 3: multipart/form-data (Compatible with OpenAI SDK)
If you are already using the official OpenAI Python SDK, the originalmultipart/form-data upload method is also supported; just change the model to gpt-image-2:
OPENAI_BASE_URL to https://api.xhuoapi.ai/v1/openai, and OPENAI_API_KEY to the acquired token:
Nano Banana Series Models
Thenano-banana series is also integrated into /openai/images/edits for editing scenarios; just change the model to any one in the table below.
| Model | Billing (Credits / request) | Suitable Scenario |
|---|---|---|
nano-banana | 0.14 | General image editing, fastest speed, lowest cost |
nano-banana-2 | 0.28 | Noticeable improvement in quality and detail |
nano-banana-pro | 0.35 | Flagship of the series, best preservation of structure, text, and style |
Important: Supported Parameters Nano Banana accesses the OpenAI protocol via an adapter layer and only supports the following parameters:model,prompt,image.
imagecan be uploaded viamultipart/form-datafile upload (internally converted todata:<mime>;base64,...for upstream), or passed as a URL string in the form field.- Parameters like
mask,n,size,response_formatare not supported and will be ignored if provided.- The return structure follows the OpenAI format (
data[].url), butcreatedis always0, nob64_jsonis returned, andrevised_promptalways equals the originalprompt.
Calling via Form + Image URL

Calling via Form + Local File
Asynchronous Callback
Thecallback_url asynchronous callback mechanism also works for nano-banana, with the same calling process as other models; see the Asynchronous Callback section below for details.
Basic Usage
Next, you can call the API using code. Below is a CURL example:authorization, which you can select directly from the dropdown list. Another parameter is model, which is the OpenAI official model category you choose to use; here we mainly have one model, details can be found in the models we provide. Another parameter is prompt, which is the prompt describing the image you want to generate. The last parameter is image, which is the path of the image to be edited, as shown below:

OPENAI_BASE_URL, which can be set to https://api.xhuoapi.ai/v1/openai, and the credential variable OPENAI_API_KEY, which is obtained from the authorization. On macOS, you can set environment variables using:
gift-basket.png generated in the current directory. The result is as follows:

dall-e-2, gpt-image-1, and gpt-image-2, with gpt-image-2 being the recommended model; see the above GPT-Image-2 Model section for details.
Asynchronous Callback
Since editing images with the OpenAI Images Edits API may take some time, if the API does not respond for a long time, the HTTP request will keep the connection open, causing additional system resource consumption. Therefore, this API also provides asynchronous callback support. The overall process is: when the client initiates a request, it additionally specifies acallback_url field. After the client sends the API request, the API immediately returns a result containing a task_id field representing the current task ID. When the task is completed, the edited image result is sent via POST JSON to the client’s specified callback_url, including the task_id field, so the task result can be associated by ID.
Below is an example to illustrate the operation.
First, the webhook callback is a service that can receive HTTP requests; developers should replace it with their own HTTP server URL. For demonstration, we use a public webhook sample site https://webhook.site/. Opening this site provides a webhook URL, as shown:
Copy this URL, which can be used as the webhook. The example URL here is https://webhook.site/3d32690d-6780-4187-a65c-870061e8c8ab.
Next, set the callback_url field to the above webhook URL and fill in the corresponding parameters, as shown below:
task_id field, and the data field includes the same image editing result as synchronous calls. The task_id field enables task association.
Error Handling
When calling the API, if an error occurs, the API will return corresponding error codes and messages, for example:400 token_mismatched: Bad request, possibly due to missing or invalid parameters.400 api_not_implemented: Bad request, possibly due to missing or invalid parameters.401 invalid_token: Unauthorized, invalid or missing authorization token.429 too_many_requests: Too many requests, rate limit exceeded.500 api_error: Internal server error, something went wrong on the server.

