Skip to main content
POST
/
v1
/
images
/
generations
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": "1:1",
    "resolution": "1K",
    "response_format": "url"
  }'
{
  "id": "task_img_abc123def456",
  "object": "generation.task",
  "model": "gpt-image-2",
  "status": "queued",
  "progress": 0,
  "created_at": 1703884800,
  "metadata": {}
}

Documentation Index

Fetch the complete documentation index at: https://docs.toapis.com/llms.txt

Use this file to discover all available pages before exploring further.

  • 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

Authorization
string
required
All endpoints require Bearer Token authenticationGet your API Key from the API Key Management PageAdd to request header:
Authorization: Bearer YOUR_API_KEY

Body

model
string
default:"gpt-image-2"
required
Image generation model nameExample: "gpt-image-2"
prompt
string
required
Text prompt for image generationMaximum 32,000 characters for GPT image models
size
string
default:"1:1"
Output image aspect ratioSupported values depend on resolution:
  • 1K: 1:1, 3:2, 2:3
  • 2K: 1:1, 3:2, 2:3, 4:3, 3:4, 5:4, 4:5, 16:9, 9:16, 2:1, 1:2, 21:9, 9:21
  • 4K: 16:9, 9:16, 2:1, 1:2, 21:9, 9:21
resolution
string
default:"1K"
Output resolution tierSupported values: 1K, 2K, 4K

Size Reference

size1K2K4K
1:11024x10242048x2048Not supported
3:21536x10242048x1360Not supported
2:31024x15361360x2048Not supported
4:3Not supported2048x1536Not supported
3:4Not supported1536x2048Not supported
5:4Not supported2560x2048Not supported
4:5Not supported2048x2560Not supported
16:9Not supported2048x11523840x2160
9:16Not supported1152x20482160x3840
2:1Not supported2688x13443840x1920
1:2Not supported1344x26881920x3840
21:9Not supported2688x11523840x1648
9:21Not supported1152x26881648x3840
n
integer
default:1
Number of images to generateDefault: 1
response_format
string
default:"url"
Response formatThe API returns image URLs, so url is the recommended value
reference_images
string[]
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
image_urls
string[]
Backward-compatible reference image fieldToAPIs automatically normalizes it to reference_images

Response

id
string
Unique task identifier for status queries
object
string
Object type, always generation.task
model
string
Model name used
status
string
Task status
  • queued
  • in_progress
  • completed
  • failed
progress
integer
Task progress percentage (0-100)
created_at
integer
Task creation timestamp (Unix timestamp)
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": "1:1",
    "resolution": "1K",
    "response_format": "url"
  }'
{
  "id": "task_img_abc123def456",
  "object": "generation.task",
  "model": "gpt-image-2",
  "status": "queued",
  "progress": 0,
  "created_at": 1703884800,
  "metadata": {}
}