- Get started
- Introduction
- Authentication
- Making requests
- Streaming
- Audio
- Batch
- Models
- Invites
- Chat
- Users
- Projects
- Project users
- Project service accounts
- Project API keys
- Audit logs
- Usage
- Project rate limits
- Completions
- Uploads
- Embeddings
- Files
- Moderations
- Assistants (v1)
- Threads (v1)
- Messages (v1)
- Runs (v1)
- Images
- Fine-tuning
Create image
POST
https://api.openai.com/v1/images/generations
Request
Authorization
Provide your bearer token in the
Authorization
header when making requests to protected resources.Example:
Authorization: Bearer ********************
Header Params
Authorization
stringÂ
optional
Example:
Bearer {{YOUR_API_KEY}}
Body Params application/json
prompt
stringÂ
required
n
integerÂ
optional
size
stringÂ
optional
256x256
, 512x512
, or 1024x1024
.response_format
stringÂ
required
url
 or b64_json
.user
stringÂ
required
Example
{
"prompt": "A colorful sunset over the mountains",
"n": 2,
"size": "1024x1024"
}
Request samples
Shell
JavaScript
Java
Swift
Go
PHP
Python
HTTP
C
C#
Objective-C
Ruby
OCaml
Dart
R
Request Request Example
Shell
JavaScript
Java
Swift
curl --location --request POST 'https://api.openai.com/v1/images/generations' \
--header 'Content-Type: application/json' \
--data-raw '{
"prompt": "A colorful sunset over the mountains",
"n": 2,
"size": "1024x1024"
}'
Responses
🟢200Create image
application/json
Body
created
integerÂ
required
data
array [object {1}]Â
required
url
stringÂ
required
Example
{
"created": 1589478378,
"data": [
{
"url": "https://..."
},
{
"url": "https://..."
}
]
}
Modified at 2024-12-13 10:20:37