Skip to main content
POST
/
v1
/
images
/
generations
Generate Images
curl --request POST \
  --url https://api.example.com/v1/images/generations \
  --header 'Content-Type: application/json' \
  --data '
{
  "prompt": "<string>",
  "model": "<string>",
  "n": 123,
  "size": "<string>",
  "quality": "<string>",
  "response_format": "<string>",
  "style": "<string>",
  "background": "<string>",
  "output_format": "<string>",
  "output_compression": 123,
  "moderation": "<string>",
  "stream": true,
  "partial_images": 123,
  "user": "<string>"
}
'
{
  "created": 123,
  "data": [
    {
      "url": "<string>",
      "b64_json": "<string>",
      "revised_prompt": "<string>"
    }
  ]
}
Generates images from text prompts using DALL-E or GPT Image models. For multimodal models like gemini-2.5-flash-image, use /v1/chat/completions instead.

Method

client.images.generate(params)

Request Parameters

prompt
string
required
A text description of the desired image(s). Maximum length:
  • 32,000 characters for gpt-image-1
  • 4,000 characters for dall-e-3
  • 1,000 characters for dall-e-2
model
string
The model to use for image generation. Options:
  • openai/dall-e-2
  • openai/dall-e-3
  • openai/gpt-image-1
Default: openai/dall-e-2 (unless a gpt-image-1-specific parameter is used)
n
number
The number of images to generate. Must be between 1 and 10. For dall-e-3, only n=1 is supported.Default: 1
size
string
The size of the generated images:
  • gpt-image-1: 1024x1024, 1536x1024 (landscape), 1024x1536 (portrait), or auto (default)
  • dall-e-2: 256x256, 512x512, or 1024x1024
  • dall-e-3: 1024x1024, 1792x1024, or 1024x1792
quality
string
The quality of the image that will be generated:
  • auto (default) - automatically select the best quality
  • high, medium, low - supported for gpt-image-1
  • hd, standard - supported for dall-e-3
  • standard - only option for dall-e-2
response_format
string
The format in which generated images are returned:
  • url - URLs valid for 60 minutes
  • b64_json - Base64-encoded JSON
Note: gpt-image-1 always returns base64-encoded images.Default: url
style
string
The style of the generated images (DALL-E 3 only):
  • vivid - hyper-real and dramatic images
  • natural - more natural, less hyper-real looking images
background
string
Set transparency for the background (gpt-image-1 only):
  • auto (default) - model automatically determines the best background
  • transparent - transparent background (requires png or webp output format)
  • opaque - opaque background
output_format
string
The format in which the generated images are returned (gpt-image-1 only):
  • png
  • jpeg
  • webp
output_compression
number
The compression level (0-100%) for generated images (gpt-image-1 only, with webp or jpeg formats).Default: 100
moderation
string
Content-moderation level for images (gpt-image-1 only):
  • auto (default) - standard filtering
  • low - less restrictive filtering
stream
boolean
Generate the image in streaming mode (gpt-image-1 only). See the Image generation guide for more information.Default: false
partial_images
number
The number of partial images to generate (0-3). Used for streaming responses. When set to 0, the response will be a single image sent in one streaming event.Note: The final image may be sent before all partial images are generated if completed more quickly.
user
string
A unique identifier representing your end-user, which can help OpenAI monitor and detect abuse. Learn more.

Response

created
number
required
Unix timestamp when images were created.
data
array
required
List of generated images.

Examples

const image = await client.images.generate({
  prompt: "A white siamese cat",
  model: "openai/dall-e-3"
});

console.log(image.data[0].url);

Build docs developers (and LLMs) love