Unified image generation API
Select the gpt-image-2 model via the model parameter
Supports text-to-image, single-reference, and multi-reference image generation
Async task management with task ID based result lookup
Important Change : For better performance and cost control, base64 image data is no longer supported in image_urls or reference_images. Please use the Upload Image API first to upload images and obtain a URL.
Authorizations
All endpoints require Bearer Token authentication Get your API Key from the API Key Management Page Add to request header: Authorization: Bearer YOUR_API_KEY
Body
model
string
default: "gpt-image-2"
required
Image generation model name Example: "gpt-image-2"
Text prompt for image generation Maximum 4000 characters
size
string
default: "1024x1024"
Output image size Common values:
1024x1024
1536x1024
1024x1536
Number of images to generate Default: 1
Response format Recommended value: b64_json
Reference image URLs for image-to-image generation ⚠️ URL format only (base64 no longer supported)
Publicly accessible URLs (http:// or https://)
You can use the Upload Image API to upload local files and get URLs
Supports single-image and multi-image reference
Backward-compatible reference image field ToAPIs automatically normalizes it to reference_images
Response
Unique task identifier for status queries
Object type, always generation.task
Task status
queued
in_progress
completed
failed
Task progress percentage (0-100)
Task creation timestamp (Unix timestamp)
cURL
cURL (Image-to-Image)
JavaScript
curl --request POST \
--url https://toapis.com/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-image-2",
"prompt": "Generate a futuristic city night poster with neon lighting and cinematic composition",
"n": 1,
"size": "1024x1024",
"response_format": "b64_json"
}'
{
"id" : "task_img_abc123def456" ,
"object" : "generation.task" ,
"model" : "gpt-image-2" ,
"status" : "queued" ,
"progress" : 0 ,
"created_at" : 1703884800 ,
"metadata" : {}
}