Flux Kontext Max API
Flux Kontext Max 的完整 API 參考,具備增強的多圖片上下文理解能力。
模型概覽
快速比較
支援的長寬比
兩種模式都支援 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
請求參數
必填
注意: 寬度:高度比例必須是以下其中之一:"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
請求參數
必填
注意: 寬度:高度比例必須是以下其中之一:"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:
{
"code": 0,
"data": {
"task_id": "{task_id}",
"task_status": "submitted",
"response_url": "https://api.flaq.ai/api/v1/image/{task_id}"
},
"message": "success"
}
輪詢回應
輪詢 /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 擅長複雜且細節豐富的場景
- 高效輪詢: 每 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
}