Grok Imagine API
Tài liệu tham khảo API đầy đủ cho các mô hình tạo ảnh Grok Imagine của xAI.
Các Biến Thể Mô Hình
API này hỗ trợ hai biến thể mô hình:
So Sánh Nhanh
Grok Imagine (Văn Bản sang Ảnh)
Endpoint
POST /api/v1/image/task
Tham Số Yêu Cầu
Bắt buộc
Ví Dụ Yêu Cầu
const response = await fetch('https://api.flaq.ai/api/v1/image/task', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model_name: 'grok-imagine',
prompt: 'A surreal landscape with floating islands and waterfalls',
width: 16,
height: 9
})
});
const { data } = await response.json();
const taskId = data.task_id;
const pollResponse = await fetch(
`https://api.flaq.ai/api/v1/image/${taskId}`,
{
headers: { 'Authorization': 'Bearer YOUR_API_KEY' }
}
);
const result = await pollResponse.json();
console.log(result.data.task_result.images[0].url);
Grok Imagine Edit (Chỉnh Sửa Ảnh)
Tham Số Yêu Cầu
Bắt buộc
Ví Dụ Yêu Cầu
{
model_name: 'grok-imagine-edit',
width: 1,
height: 1,
image_url_list: ['https://example.com/photo.jpg'],
prompt: 'Change the sky to a dramatic sunset with orange and purple hues'
}
Định Dạng Phản Hồi
Phản Hồi Ban Đầu
{
"code": 0,
"data": {
"task_id": "{task_id}",
"task_status": "submitted",
"response_url": "https://api.flaq.ai/api/v1/image/{task_id}"
},
"message": "success"
}
Phản Hồi Polling
Poll GET /api/v1/image/{task_id} để kiểm tra trạng thái:
{
"code": 0,
"data": {
"task_id": "{task_id}",
"task_status": "succeed",
"task_status_msg": null,
"response_url": "https://api.flaq.ai/api/v1/image/{task_id}",
"task_result": {
"credit": 0.0997,
"images": [
{
"url": "https://example.com/generated-image.jpeg"
}
]
}
},
"message": "success"
}
Giá Trị Trạng Thái
submitted: Tác vụ đã được chấp nhận
processing: Đang tạo ảnh
succeed: Tạo ảnh hoàn tất
failed: Tạo ảnh thất bại
Thời Gian Xử Lý
Thời gian xử lý thông thường: 15-60 giây.
Thực Hành Tốt Nhất
- Prompt Sáng Tạo: Grok Imagine phản hồi tốt với các mô tả chi tiết và giàu trí tưởng tượng
- Độ Cụ Thể Khi Chỉnh Sửa: Khi chỉnh sửa, hãy mô tả rõ ràng những gì cần thay đổi và những gì cần giữ nguyên