Skip to main content
POST
/
v1
/
images
/
generations
Generate Image
curl --request POST \
  --url https://api.example.com/v1/images/generations \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "<string>",
  "prompt": "<string>",
  "background": "<string>",
  "moderation": "<string>",
  "n": 1,
  "output_compression": 1,
  "output_format": "<string>",
  "quality": "<string>",
  "response_format": "<string>",
  "size": "<string>",
  "style": "<string>"
}
'
{
  "data": [
    {
      "b64_json": "<string>",
      "revised_prompt": "<string>",
      "url": "<string>"
    }
  ],
  "background": "<string>",
  "created": 1,
  "output_format": "<string>",
  "quality": "<string>",
  "size": "<string>",
  "usage": {
    "input_tokens": 1,
    "input_tokens_details": {
      "image_tokens": 1,
      "text_tokens": 1
    },
    "output_tokens": 1,
    "total_tokens": 1
  }
}

Body

application/json

Request parameters for generating images using AI models

model
string
required

The model to use for image generation (e.g., "dall-e-2", "dall-e-3", "imagen-3.0-generate-001").

prompt
string
required

A text description of the desired image(s).

background
string | null

The background color to use for transparency. Defaults to "auto". OpenAI only.

moderation
string | null

The moderation level to apply to the generated image. OpenAI only.

n
integer<int32> | null

The number of images to generate.

Required range: x >= 0
output_compression
integer<int32> | null

The compression level for the output image, ranging from 0 to 100. Higher values mean more compression. OpenAI only.

Required range: x >= 0
output_format
string | null

The format of the output image (e.g., "png", "jpeg"). OpenAI only.

quality
string | null

The quality of the image that will be generated. "hd" creates images with finer details and greater consistency. Not supported for all models.

response_format
string | null

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 is generated.

size
string | null

The size of the generated images. Not supported for all models.

style
string | null

The style of the generated images. Must be one of "vivid" or "natural". Vivid causes the model to lean towards generating hyper-real and dramatic images. Natural causes the model to produce more natural, less hyper-real looking images. Not supported for all models.

Response

Image generated successfully

Response from an image generation request

data
object[]
required

Array containing the generated image(s).

background
string | null

The background color used for transparency. OpenAI only.

created
integer<int64> | null

The Unix timestamp (in seconds) of when the image was generated.

Required range: x >= 0
output_format
string | null

The format of the output image. OpenAI only.

quality
string | null

The quality setting used for image generation. OpenAI only.

size
string | null

The size of the generated image. OpenAI only.

usage
object

Token usage information for the image generation request. OpenAI only.