Grok Imagine API
เอกสารอ้างอิง API ฉบับสมบูรณ์สำหรับโมเดลสร้างรูปภาพ Grok Imagine โดย xAI.
ตัวเลือกโมเดล {#}
API นี้รองรับโมเดล 2 ตัวเลือก:
เปรียบเทียบอย่างรวดเร็ว
Grok Imagine (ข้อความเป็นรูปภาพ)
จุดเชื่อมต่อ
POST /api/v1/image/task
พารามิเตอร์คำขอ
จำเป็น
ตัวอย่างคำขอ
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 (การแก้ไขรูปภาพ)
พารามิเตอร์คำขอ
จำเป็น
ตัวอย่างคำขอ
{
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'
}
รูปแบบการตอบกลับ
การตอบกลับเริ่มต้น
{
"code": 0,
"data": {
"task_id": "{task_id}",
"task_status": "submitted",
"response_url": "https://api.flaq.ai/api/v1/image/{task_id}"
},
"message": "success"
}
การตอบกลับจากการ Poll
Poll GET /api/v1/image/{task_id} เพื่อตรวจสอบสถานะ:
{
"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"
}
ค่าสถานะ
submitted: รับงานแล้ว
processing: กำลังสร้างรูปภาพ
succeed: การสร้างรูปภาพเสร็จสมบูรณ์
failed: การสร้างรูปภาพล้มเหลว
เวลาประมวลผล
เวลาประมวลผลโดยทั่วไป: 15-60 วินาที.
แนวทางปฏิบัติที่ดี
- พรอมต์เชิงสร้างสรรค์: Grok Imagine ตอบสนองได้ดีกับคำอธิบายที่มีจินตนาการและละเอียด
- ความชัดเจนในการแก้ไข: สำหรับการแก้ไข ให้อธิบายชัดเจนว่าต้องการเปลี่ยนอะไรและคงอะไรไว้