Overview
Use the gpt-image-2 model for text-to-image generation. It generates images based on text prompts and returns the image results simultaneously.
API details
Constraints
- The caller must have an API Key. For more information, see Manage AI API Keys.
Request path
POST {BASE_URL}/api/v1/images/generations
Request header
Name |
Required |
Example value |
Description |
|---|---|---|---|
| Authorization | Yes | Bearer {token} | Authentication information |
| Content-Type | Yes | application/json | Request body format |
Request parameters
Path
Name |
Type |
Required |
Example value |
Description |
|---|---|---|---|---|
| None | This API has no path parameters. |
Query
Name |
Type |
Required |
Example value |
Description |
|---|---|---|---|---|
| None | This API has no query parameters. |
Body
Name |
Type |
Required |
Example value |
Description |
|---|---|---|---|---|
| model | string | Yes | gpt-image-2 | Model name, which is fixed asgpt-image-2 |
| prompt | string | Yes | A simple red apple on a white table, photorealistic | Prompt for generating an image |
| size | string | Yes | 1024x1024 | Image size |
| n | integer | Yes | 1 | Number of generated images |
Response
Response parameters
Name |
Type |
Description |
|---|---|---|
| created | integer | Creation timestamp |
| data | array[object] | Generated images |
| usage | object | Usage information |
data
Name |
Type |
Description |
|---|---|---|
| url | string | Image URL |
| b64_json | string | Base64-encoded image data |
| revised_prompt | string | Revised prompt |
Request example
curl -sS -X POST "${BASE_URL}/api/v1/images/generations" \
-H "Authorization: Bearer ${API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A simple red apple on a white table, photorealistic",
"size": "1024x1024",
"n": 1
}'
Response example
Successful response (200)
{
"created": 1780000000,
"data": [
{
"url": "https://...",
"b64_json": "...",
"revised_prompt": "..."
}
],
"usage": {}
}
Error response
{
"error": {
"message": "error message",
"type": "error_type",
"code": "error_code"
}
}
