API Flux Kontext Max
เอกสารอ้างอิง API ฉบับสมบูรณ์สำหรับ Flux Kontext Max พร้อมความเข้าใจบริบทหลายภาพที่ได้รับการปรับปรุง
ภาพรวมโมเดล {#}
เปรียบเทียบอย่างรวดเร็ว
อัตราส่วนภาพที่รองรับ
ทั้งสองโหมดรองรับอัตราส่วนภาพ 9 แบบ:
1:1, 16:9, 9:16, 3:2, 2:3, 4:3, 3:4, 21:9, 9:21
ค่าใช้จ่าย
Flux Kontext Max (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-max',
prompt: 'A futuristic cityscape at night with neon lights',
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 Max (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-max',
prompt: 'Enhance this portrait with cinematic lighting',
width: 3,
height: 4,
image_url_list: ['https://example.com/portrait.jpg']
}
ตัวอย่างการจัดองค์ประกอบหลายภาพ
{
model_name: 'flux-kontext-max',
prompt: 'Merge these architectural photos into a unified panorama',
width: 21,
height: 9,
image_url_list: ['https://example.com/arch1.jpg', 'https://example.com/arch2.jpg', 'https://example.com/arch3.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.08,
"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-max"
}
จำนวนภาพมากเกินไป
{
"code": 400,
"message": "Maximum 5 images allowed"
}
แนวทางปฏิบัติที่ดีที่สุด
เคล็ดลับ Text-to-Image
- พรอมต์อย่างละเอียด: ให้คำอธิบายที่ชัดเจนและละเอียดเพื่อผลลัพธ์ที่ดีที่สุด
- อัตราส่วนภาพ: เลือกอัตราส่วนภาพที่เหมาะสมกับกรณีใช้งานของคุณ
- ฉากซับซ้อน: Flux Kontext Max โดดเด่นกับฉากที่ซับซ้อนและมีรายละเอียดสูง
- Polling อย่างมีประสิทธิภาพ: ตรวจสอบสถานะทุก 2-3 วินาที
เคล็ดลับ Image-to-Image
- เข้าใจบริบท: ใช้อินพุตหลายภาพเพื่อการสร้างที่มีบริบทเข้มข้น
- อินพุตคุณภาพสูง: ใช้ภาพต้นทางความละเอียดสูงเพื่อผลลัพธ์ที่ดีที่สุด
- เป้าหมายการแปลงที่ชัดเจน: อธิบายผลลัพธ์ที่ต้องการอย่างแม่นยำ
- การประสานหลายภาพ: รวมภาพได้สูงสุด 5 ภาพสำหรับองค์ประกอบที่ซับซ้อน
ตัวอย่างกรณีใช้งาน
การถ่ายภาพผลิตภัณฑ์ระดับไฮเอนด์
{
model_name: 'flux-kontext-max',
prompt: 'Ultra-realistic product shot of diamond jewelry on black velvet',
width: 4,
height: 3
}
การสร้างภาพสถาปัตยกรรม
{
model_name: 'flux-kontext-max',
prompt: 'Modern minimalist interior with natural lighting',
width: 16,
height: 9
}
พาโนรามาหลายภาพ
{
model_name: 'flux-kontext-max',
image_url_list: ['view1.jpg', 'view2.jpg', 'view3.jpg', 'view4.jpg'],
prompt: 'Seamless 360-degree panorama of mountain landscape',
width: 21,
height: 9
}
การถ่ายโอนสไตล์ขั้นสูง
{
model_name: 'flux-kontext-max',
image_url_list: ['photo.jpg'],
prompt: 'Transform into oil painting with Van Gogh style brushwork',
width: 1,
height: 1
}