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(文生图)
接口地址
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(图生图)
接口地址
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:
{
"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(图生图模式)
{
"code": 400,
"message": "image_url_list is required for flux-kontext-max"
}
图像数量过多
{
"code": 400,
"message": "Maximum 5 images allowed"
}
最佳实践
文生图技巧
- 详细的提示词: 提供清晰、详细的描述以获得最佳效果
- 宽高比: 根据使用场景选择合适的宽高比
- 复杂场景: Flux Kontext Max 擅长处理复杂、细节丰富的场景
- 高效轮询: 每 2-3 秒检查一次状态
图生图技巧
- 上下文感知: 利用多图像输入实现丰富的上下文生成
- 高质量输入: 使用高分辨率源图像以获得最佳效果
- 明确的转换目标: 精确描述期望的输出结果
- 多图协同: 组合最多 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
}