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
ID of the model to use. Use gpt-4o or models with image generation capability.
A list of messages describing the image you want to generate.
Maximum number of tokens to generate in the response.
Sampling temperature between 0 and 2.
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
Image Size Options
| Size | Description |
|---|
| 256x256 | Small square image |
| 512x512 | Medium square image |
| 1024x1024 | Large square image (default) |
| 1792x1024 | Wide landscape image |
| 1024x1792 | Tall portrait image |