Skip to main content
Use the model ID gpt-image-2 with the generation or editing endpoint. Select the Direct resource group before sending requests.
GPT Image 2 returns Base64-encoded image data in data[].b64_json. Do not send the DALL·E-only response_format parameter. Select the tab for your workflow.

Generate images

POST /v1/images/generations
cURL

Request headers

string
required
Bearer authentication in the form Bearer YOUR_API_KEY.
string
default:"application/json"
required
Data exchange format.

Request body

string
required
Model ID. Must be gpt-image-2.
string
required
Description of the image to generate. Length: 1–32,000 characters.
integer
default:1
Number of images to generate. Supported range: 1–10.
string
default:"auto"
auto or custom WIDTHxHEIGHT dimensions. Width and height must be divisible by 16, the aspect ratio must be from 1:3 through 3:1, neither edge may exceed 3,840 pixels, and total pixels must be from 655,360 through 8,294,400. Resolutions above 2560x1440 are experimental.
string
Rendering quality: low, medium, or high.
string
default:"auto"
Background mode: auto, opaque, or transparent. Transparent output is in preview and requires PNG or WebP.
string
default:"png"
Output format: png, jpeg, or webp.
integer
default:100
JPEG or WebP compression level from 0 through 100. Ignored for PNG output.
string
default:"auto"
Moderation strictness: auto or low.

Generation response

200
integer
Creation time as a Unix timestamp in seconds.
object[]
Generated image results.
string
Base64-encoded image data.
string
Model that produced the response.
object
Token usage for the request.
integer
Total text and image input tokens.
object
Input token breakdown by text and image.
integer
Image input tokens.
integer
Text input tokens.
integer
Total output tokens.
object
Output token breakdown by text and image.
integer
Image output tokens.
integer
Text output tokens.
integer
Total input and output tokens.

Validation rules

  • background: "transparent" requires output_format: "png" or output_format: "webp".
  • Custom dimensions must satisfy the divisibility, aspect-ratio, edge-length, and total-pixel limits described above.
  • output_compression applies only to JPEG and WebP output.
  • GPT Image 2 returns Base64 image data; URL output through response_format is not supported.
See the OpenAI GPT Image 2 model page, create image reference, and create image edit reference for the upstream contract.