POST
/
v1
/
chat
/
completions
Chat Completions Image Generation (Non-Stream)
curl --request POST \
  --url https://api.example.com/v1/chat/completions \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "<string>",
  "messages": [
    {}
  ],
  "max_tokens": 123,
  "temperature": 123,
  "n": 123,
  "size": "<string>"
}
'
Generate images based on text descriptions through the chat completions interface.

Overview

This endpoint allows you to generate images using DALL-E models through the chat completions API. The model will create images based on your text descriptions and return them in the response.

Authentication

All requests require a Bearer token in the Authorization header:
Authorization: Bearer YOUR_API_KEY

Request Parameters

model
string
required
ID of the model to use. Use gpt-4o or models with image generation capability.
messages
array
required
A list of messages describing the image you want to generate.
max_tokens
integer
Maximum number of tokens to generate in the response.
temperature
number
default:"1"
Sampling temperature between 0 and 2.
n
integer
default:"1"
Number of images to generate.
size
string
default:"1024x1024"
Size of the generated image. Options: 256x256, 512x512, 1024x1024, 1792x1024, 1024x1792.

Request Example

curl -X POST https://api.example.com/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {
        "role": "user",
        "content": "Generate an image of a futuristic city with flying cars and neon lights at night"
      }
    ],
    "max_tokens": 4096
  }'

Response Example

{
  "id": "chatcmpl-123",
  "object": "chat.completion",
  "created": 1677652288,
  "model": "gpt-4o",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": [
          {
            "type": "image_url",
            "image_url": {
              "url": "https://example.com/generated-image.png"
            }
          },
          {
            "type": "text",
            "text": "Here is the generated image of a futuristic city with flying cars and neon lights at night."
          }
        ]
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 25,
    "completion_tokens": 150,
    "total_tokens": 175
  }
}

Available Models

  • gpt-4o
  • dall-e-3
  • dall-e-2

Image Size Options

SizeDescription
256x256Small square image
512x512Medium square image
1024x1024Large square image (default)
1792x1024Wide landscape image
1024x1792Tall portrait image