Skip to main content
POST
Generate Images
Creates an image given a prompt.

Method Signature

Parameters

string
required
A text description of the desired image(s). The maximum length is:
  • 32000 characters for GPT image models
  • 4000 characters for dall-e-3
  • 1000 characters for dall-e-2
string
The model to use for image generation. Options:
  • dall-e-2
  • dall-e-3
  • gpt-image-1
  • gpt-image-1-mini
  • gpt-image-1.5
  • chatgpt-image-latest
Defaults to dall-e-2 unless a parameter specific to the GPT image models is used.
integer
The number of images to generate. Must be between 1 and 10. For dall-e-3, only n=1 is supported.
string
The quality of the image that will be generated:
  • auto (default) - automatically select the best quality for the given model
  • high, medium, low - supported for GPT image models
  • hd, standard - supported for dall-e-3
  • standard - only option for dall-e-2
string
The format in which the generated images are returned. Must be one of url or b64_json. URLs are only valid for 60 minutes after the image has been generated.This parameter is only supported for dall-e-2 and dall-e-3 - GPT image models always return base64-encoded images.
string
The size of the generated images:
  • GPT image models: 1024x1024, 1536x1024 (landscape), 1024x1536 (portrait), or auto (default)
  • dall-e-2: 256x256, 512x512, or 1024x1024
  • dall-e-3: 1024x1024, 1792x1024, or 1024x1792
string
The style of the generated images. Only supported for dall-e-3:
  • vivid - generates hyper-real and dramatic images
  • natural - produces more natural, less hyper-real looking images
string
Allows to set transparency for the background of the generated image(s). Only supported for GPT image models:
  • transparent
  • opaque
  • auto (default) - model automatically determines the best background
If transparent, the output format needs to support transparency (png or webp).
string
The format in which the generated images are returned. Only supported for GPT image models:
  • png (default)
  • jpeg
  • webp
integer
The compression level (0-100%) for the generated images. Only supported for GPT image models with webp or jpeg output formats. Defaults to 100.
string
Control the content-moderation level for images generated by the GPT image models:
  • auto (default)
  • low - less restrictive filtering
boolean
Generate the image in streaming mode. Defaults to false. Only supported for GPT image models. See the Image generation guide for more information.
integer
The number of partial images to generate. Used for streaming responses that return partial images. Value must be between 0 and 3. When set to 0, the response will be a single image sent in one streaming event.Note that the final image may be sent before the full number of partial images are generated if the full image is generated more quickly.
string
A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more.

Returns

Returns an ImagesResponse object containing the generated images.
integer
The Unix timestamp (in seconds) of when the image was created.
array
The list of generated images.
object
For gpt-image-1 only, the token usage information for the image generation.

Examples

Generate with DALL-E 3 (URL response)

Generate with DALL-E 2 (base64 response)

Generate with GPT Image model

Streaming generation