AI Image

POSThttps://sangtao.ai/api/v2/images/generate

Reference for AI Image.

Generate AI images from a text prompt. Returns a jobId — poll GET /api/v2/jobs/{jobId} for results.

Request Body

FieldTypeDescription
model*stringModel slug from GET /api/v2/models?category=Image
prompt*stringText description of the image to generate
numImagesintNumber of images to generate (1-4). Default: 1
sizestringImage size. Depends on model, e.g. "1024x1024"
refImageUrlsstring[]Reference image URLs for visual consistency. Upload first via POST /api/v2/images/upload
tierstringGeneration tier: "standard" (default, 1x credit) or "vip1" (higher quality, 5x credit). Affects routing and quality
optionsobjectPer-model options. Keys from GET /api/v2/models/{slug} config. E.g. aspectRatio, outputFormat, resolution, style
Tip: Use GET /api/v2/models?category=Image to list all available image models and their config options.

cURL

bash
curl -X POST https://sangtao.ai/api/v2/images/generate \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "nano-banana-pro",
    "prompt": "A cozy Vietnamese coffee shop in Hanoi Old Quarter, morning light",
    "numImages": 2,
    "options": { "aspectRatio": "16:9" }
  }'

JSON Body

json
{
  "model": "nano-banana-pro",
  "prompt": "A cozy Vietnamese coffee shop in Hanoi Old Quarter, morning light",
  "numImages": 2,
  "options": {
    "aspectRatio": "16:9",
    "outputFormat": "jpeg",
    "resolution": "1K"
  }
}

Response

Returns a jobId. Poll the job status endpoint to get results:

json
{
  "success": true,
  "data": {
    "jobId": "img-abc123"
  }
}

Job Polling

Poll GET /api/v2/jobs/{jobId} every 3 seconds until status is "complete" or "error".

json
// GET /api/v2/jobs/{jobId}
{
  "success": true,
  "data": {
    "status": "complete",
    "resultImages": [
      "https://cdn.sangtao.ai/images/result1.jpg",
      "https://cdn.sangtao.ai/images/result2.jpg"
    ]
  }
}
Note: Image results are in the resultImages array. Each URL is a direct link to the generated image.

Error Codes

CodeWhen
400Invalid input (story too short/long, model/voice not found...)
401Unauthorized — missing or invalid API key / token
402Insufficient credits or premium voice requires top-up
429Already 4 jobs running concurrently
503System is processing too many requests. Please retry after 30 seconds