Skip to main content
OpenAI image editing service allows you to input any number of images and instructions, outputting the modified images. Currently, the API supports 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-data file uploads, gpt-image-2 also 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 size parameter; 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 WIDTHxHEIGHT you provide.
Upstream hard constraints on custom sizes also apply: width and height must be multiples of 16, the longer side ≤ 3840, and total pixels ≤ 8,294,400.
For example: if the original image is 1024x1024 and size is set to 2048x2048, the model will redraw and output a 2K image according to the editing instructions, billed at the “other” tier; if size is 3840x2160, it outputs a 4K landscape image, also billed at the “other” tier; if size is auto or omitted, billing is at the 1K standard price.
About the n parameter The gpt-image-2 editing API currently does not support n > 1: this parameter is silently ignored. Whether you pass n=1 or n=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 to gpt-image-1 / gpt-image-1.5 and the nano-banana / nano-banana-2 / nano-banana-pro series. dall-e-2 is currently the only editing model that natively supports n > 1.
Below are two real examples from different perspectives showcasing the editing capabilities of gpt-image-2. Send the request directly as application/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:

We want to convert it to a “dark mode” color scheme. You can call the API like this:
Or using Python:
The response is as follows:
The edited image is shown below:

You can see that the module structure, information sections, and typography are strictly preserved, with only the color scheme inverted to a dark theme.
Tip: The image field 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 by gpt-image-2):

Call:
Editing result (task_id: e9544dba-727e-44a2-81e1-223d49869380):

You can see that the style and environment are completely replaced as per the prompt, but the number of books on each shelf (1 / 3 / 7) is strictly preserved, and a small succulent plant is added as requested.

Method 3: multipart/form-data (Compatible with OpenAI SDK)

If you are already using the official OpenAI Python SDK, the original multipart/form-data upload method is also supported; just change the model to gpt-image-2:
When using the SDK, you need to import two environment variables first: set OPENAI_BASE_URL to https://api.xhuoapi.ai/v1/openai, and OPENAI_API_KEY to the acquired token:

Nano Banana Series Models

The nano-banana series is also integrated into /openai/images/edits for editing scenarios; just change the model to any one in the table below.
Important: Supported Parameters Nano Banana accesses the OpenAI protocol via an adapter layer and only supports the following parameters: model, prompt, image.
  • image can be uploaded via multipart/form-data file upload (internally converted to data:<mime>;base64,... for upstream), or passed as a URL string in the form field.
  • Parameters like mask, n, size, response_format are not supported and will be ignored if provided.
  • The return structure follows the OpenAI format (data[].url), but created is always 0, no b64_json is returned, and revised_prompt always equals the original prompt.

Calling via Form + Image URL

Response:
Edited image:

Calling via Form + Local File

Asynchronous Callback

The callback_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:
When using this interface for the first time, you need to fill in at least four items: one is 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:

Equivalent Python sample code:
When calling from Python, you need to import two environment variables first: 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:
After calling, you will find a file named gift-basket.png generated in the current directory. The result is as follows:

Thus, we have completed the image editing operation. Currently, the Edits API supports three models: 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 a callback_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:
After calling, you will immediately get a result like:
After a short wait, you can observe the edited image result on the webhook URL, with content like:
You can see the result contains a 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.

Error Response Example

Conclusion

Through this document, you have learned how to easily use the official OpenAI image editing features via the OpenAI Images Edits API. We hope this document helps you better integrate and use this API. If you have any questions, please feel free to contact our technical support team.