gpt-image-2

This documentation is valid for the following list of our models:

  • openai/gpt-image-2

Model Overview

As of late April 2026, this is the most advanced and capable image generation model available from OpenAI. It is designed for high-quality text-to-image generation and image editing, supporting prompt-based rendering, structured edits, and efficient token usage with caching.

How to Make a Call

Step-by-Step Instructions

1️ Setup You Can’t Skip

▪️ Create an Account: Visit the AI/ML API website and create an account (if you don’t have one yet). ▪️ Generate an API Key: After logging in, navigate to your account dashboard and generate your API key. Ensure the key is enabled on the UI.

2️ Copy the code example

At the bottom of this page, you'll find a code example that shows how to structure the request. Choose the code snippet in your preferred programming language and copy it into your development environment.

3️ Modify the code example

▪️ Replace <YOUR_AIMLAPI_KEY> with your actual AI/ML API key. ▪️ Adjust the input field used by this model (for example, prompt, input text, instructions, media source, or other model-specific input) to match your request.

4️ (Optional) Adjust other optional parameters if needed

Only the required parameters shown in the example are needed to run the request, but you can include optional parameters to fine-tune behavior. Below, you can find the corresponding API schema, which lists all available parameters and usage notes.

5️ Run your modified code

Run your modified code inside your development environment. Response time depends on many factors, but for simple requests it rarely exceeds a few seconds.

API Schemas

Generate image

post
Body
modelstring · enumRequiredPossible values:
promptstring · max: 32000Required

The text prompt describing the content, style, or composition of the image to be generated.

sizestring · enumOptional

The size of the generated image.

Default: 1024x1024Possible values:
qualitystring · enumOptional

The quality of the image that will be generated.

Default: mediumPossible values:
output_formatstring · enumOptional

The format of the generated image.

Default: pngPossible values:
backgroundstring · enumOptional

Allows to set transparency for the background of the generated image(s). When auto is used, the model will automatically determine the best background for the image. If transparent, the output format needs to support transparency, so it should be set to either png (default value) or webp.

Default: autoPossible values:
moderationstring · enumOptional

Control the content-moderation level for images.

Default: autoPossible values:
nnumber · enumOptional

The number of images to generate.

Default: 1Possible values:
output_compressioninteger · max: 100Optional

Compression level (0-100%), applies to JPEG and WebP only.

Default: 100
response_formatstring · enumOptional

The format in which the generated images are returned.

Default: urlPossible values:
Responses
200Success
application/json
post
/v1/images/generations
200Success

Edit image

post
Body
modelstring · enumRequiredPossible values:
promptstring · max: 32000Required

The text prompt describing the content, style, or composition of the image to be generated.

imageany ofRequired

One or multiple images to edit. Each must be a local file (png, webp, or jpg), up to 50MB. Maximum 16 images.

objectOptional
or
object[] · max: 16Optional
sizestring · enumOptional

The size of the generated image.

Default: 1024x1024Possible values:
qualitystring · enumOptional

The quality of the image that will be generated.

Default: mediumPossible values:
output_formatstring · enumOptional

The format of the generated image.

Default: pngPossible values:
maskobjectOptional

A local PNG file used as a mask. Transparent areas define where the image will be edited. Must be under 4MB and match the image dimensions.

backgroundstring · enumOptional

Allows to set transparency for the background of the generated image(s). When auto is used, the model will automatically determine the best background for the image. If transparent, the output format needs to support transparency, so it should be set to either png (default value) or webp.

Default: autoPossible values:
nnumber · min: 1 · max: 10Optional

The number of images to generate.

Default: 1
output_compressioninteger · max: 100Optional

Compression level (0-100%), applies to JPEG and WebP only.

Default: 100
response_formatstring · enumOptional

The format in which the generated images are returned.

Default: urlPossible values:
Responses
200Success
application/json
200Success

Code Examples

Generate image

Let's generate an image of the specified size using a simple prompt.

Response

We obtained the following 1536×1024 image by running this code example (~45 s):

Edit image: Combine images

Let's generate an image using two input images and a prompt that defines how they should be edited.

Our input images

t-rex.png

crown.png

Response

We obtained the following 1024x1024 image by running this code example (~ 1 min 18 s):

Last updated

Was this helpful?