API Flux Kontext Pro
เอกสารอ้างอิง API ฉบับสมบูรณ์สำหรับ Flux Kontext Pro พร้อมความเข้าใจบริบทหลายภาพ
ภาพรวมโมเดล {#}
เปรียบเทียบอย่างรวดเร็ว
อัตราส่วนภาพที่รองรับ
ทั้งสองโหมดรองรับอัตราส่วนภาพ 9 แบบ:
1:1, 16:9, 9:16, 3:2, 2:3, 4:3, 3:4, 21:9, 9:21
ค่าใช้จ่าย
Flux Kontext Pro (Text-to-Image)
ปลายทาง
POST /api/v1/image/task
การยืนยันตัวตน
Authorization: Bearer YOUR_API_KEY
พารามิเตอร์คำขอ
จำเป็น
หมายเหตุ: อัตราส่วน width:height ต้องเป็นหนึ่งในรายการต่อไปนี้: "1:1", "16:9", "9:16", "3:2", "2:3", "4:3", "3:4", "21:9", "9:21"
ตัวอย่างคำขอ
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: 'flux-kontext-pro',
prompt: 'A serene mountain landscape at sunset',
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);
Flux Kontext Pro (Image-to-Image)
ปลายทาง
POST /api/v1/image/task
พารามิเตอร์คำขอ
จำเป็น
หมายเหตุ: อัตราส่วน width:height ต้องเป็นหนึ่งในรายการต่อไปนี้: "1:1", "16:9", "9:16", "3:2", "2:3", "4:3", "3:4", "21:9", "9:21"
ตัวอย่างการแก้ไขภาพเดี่ยว
{
model_name: 'flux-kontext-pro',
prompt: 'Transform this photo into a watercolor painting',
width: 16,
height: 9,
image_url_list: ['https://example.com/image.jpg']
}
ตัวอย่างการจัดองค์ประกอบหลายภาพ
{
model_name: 'flux-kontext-pro',
prompt: 'Combine these images into a cohesive landscape scene',
width: 16,
height: 9,
image_url_list: ['https://example.com/image1.jpg', 'https://example.com/image2.jpg', 'https://example.com/image3.jpg']
}
รูปแบบการตอบกลับ
การตอบกลับเริ่มต้น
ทั้งสองโหมดจะส่งคืน task_id สำหรับการ polling:
{
"code": 0,
"data": {
"task_id": "{task_id}",
"task_status": "submitted",
"response_url": "https://api.flaq.ai/api/v1/image/{task_id}"
},
"message": "success"
}
การตอบกลับจากการ polling
Poll /api/v1/image/{taskId} เพื่อตรวจสอบสถานะ:
{
"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.04,
"images": [
{
"url": "https://example.com/generated-image.jpeg"
}
]
}
},
"message": "success"
}
ค่าสถานะ
submitted: รับงานแล้ว
processing: กำลังสร้าง
succeed: สร้างสำเร็จ
failed: สร้างล้มเหลว
การจัดการข้อผิดพลาด
ข้อผิดพลาดทั่วไป
อัตราส่วนภาพไม่ถูกต้อง
{
"code": 400,
"message": "Ratio must be one of: 1:1, 16:9, 9:16, 3:2, 2:3, 4:3, 3:4, 21:9, 9:21"
}
ไม่มี URL ภาพ (โหมด Image-to-Image)
{
"code": 400,
"message": "image_url_list is required for flux-kontext-pro"
}
จำนวนภาพมากเกินไป
{
"code": 400,
"message": "Maximum 5 images allowed"
}
แนวทางปฏิบัติที่ดีที่สุด
เคล็ดลับ Text-to-Image
- ระบุให้ชัดเจน: ใส่รายละเอียดของตัวแบบ สไตล์ แสง และองค์ประกอบภาพ
- การเลือกอัตราส่วนภาพ: เลือกอัตราส่วนตามกรณีใช้งานของคุณ (16:9 สำหรับเว็บ, 9:16 สำหรับมือถือ)
- คุณภาพพรอมต์: โดยทั่วไปพรอมต์ที่ละเอียดกว่าจะให้ผลลัพธ์ที่ดีกว่า
- Polling อย่างมีประสิทธิภาพ: ตรวจสอบสถานะทุก 2-3 วินาที
เคล็ดลับ Image-to-Image
- คำสั่งชัดเจน: ระบุการแปลงที่ต้องการให้ชัดเจน
- บริบทหลายภาพ: สามารถรวมภาพได้สูงสุด 5 ภาพเพื่อการสร้างที่เข้าใจบริบท
- การนำทางด้วยพรอมต์: อธิบายผลลัพธ์ที่ต้องการ ไม่ใช่แค่การเปลี่ยนแปลง
- คุณภาพภาพ: ภาพอินพุตคุณภาพสูงกว่าจะให้ผลลัพธ์ที่ดีกว่า
ตัวอย่างกรณีใช้งาน
การถ่ายภาพผลิตภัณฑ์
{
model_name: 'flux-kontext-pro',
prompt: 'Professional product shot of luxury watch on marble surface',
width: 4,
height: 3
}
คอลลาจหลายภาพ
{
model_name: 'flux-kontext-pro',
image_url_list: ['photo1.jpg', 'photo2.jpg', 'photo3.jpg'],
prompt: 'Create a seamless collage with these vacation photos',
width: 16,
height: 9
}
การถ่ายโอนสไตล์
{
model_name: 'flux-kontext-pro',
image_url_list: ['photo.jpg'],
prompt: 'Transform into impressionist painting style',
width: 1,
height: 1
}