Tạo ảnh AI
POST
https://sangtao.ai/api/v2/images/generateTài liệu cho Tạo ảnh AI.
Tạo ảnh AI từ mô tả text. Trả về jobId — poll GET /api/v2/jobs/{jobId} để lấy kết quả.
Nội dung request
| Field | Type | Description |
|---|---|---|
| model* | string | Model slug từ GET /api/v2/models?category=Image |
| prompt* | string | Mô tả hình ảnh cần tạo |
| numImages | int | Số ảnh tạo ra (1-4). Mặc định: 1 |
| size | string | Kích thước ảnh. Phụ thuộc model, ví dụ "1024x1024" |
| refImageUrls | string[] | URL ảnh tham chiếu. Upload trước qua POST /api/v2/images/upload |
| tier | string | Tier tạo ảnh: "standard" (mặc định, 1x credit) hoặc "vip1" (chất lượng cao hơn, 5x credit). Ảnh hưởng routing và chất lượng |
| options | object | Options theo model. Keys từ GET /api/v2/models/{slug} config. Ví dụ: aspectRatio, outputFormat, resolution, style |
Tip: Dùng GET /api/v2/models?category=Image để xem danh sách model và 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"
}
}Phản hồi
Trả về jobId. Poll endpoint job status để lấy kết quả:
json
{
"success": true,
"data": {
"jobId": "img-abc123"
}
}Theo dõi tiến độ
Poll GET /api/v2/jobs/{jobId} mỗi 3 giây cho đến khi status là "complete" hoặc "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: Kết quả ảnh nằm trong mảng resultImages. Mỗi URL là link trực tiếp đến ảnh đã tạo.
Mã lỗi
| Mã | Khi nào |
|---|---|
| 400 | Input không hợp lệ (story quá ngắn/dài, model/voice không tồn tại...) |
| 401 | Chưa xác thực — thiếu hoặc sai API key / token |
| 402 | Không đủ credit hoặc voice cao cấp cần nạp tiền |
| 429 | Đã có 4 job đang chạy cùng lúc |
| 503 | Hệ thống đang xử lý nhiều yêu cầu cùng lúc. Vui lòng thử lại sau 30 giây |