Wan 2.7 Image API
Alibaba 提供支持的 Wan 2.7 图像生成模型完整 API 参考。
模型变体
此 API 支持四个模型变体:
快速对比
支持的宽高比
Standard 和 Pro 模型均支持 7 种宽高比:
16:9, 9:16, 1:1, 4:3, 3:4, 3:2, 2:3
Wan 2.7 Image(Text-to-Image)
端点
POST /api/v1/image/task
身份验证
Authorization: Bearer YOUR_API_KEY
请求参数
必填
注意: width:height 比例必须是以下之一:16:9, 9:16, 1:1, 4:3, 3:4, 3:2, 2:3
可选
示例请求
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: 'wan-v2.7-image',
prompt: 'A serene landscape with mountains and a lake 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);
Wan 2.7 Image Edit(Image Editing)
端点
POST /api/v1/image/task
请求参数
必填
注意: width:height 比例必须是以下之一:16:9, 9:16, 1:1, 4:3, 3:4, 3:2, 2:3
可选
单图编辑示例
{
model_name: 'wan-v2.7-image-edit',
prompt: 'Change the background to a beach scene',
width: 16,
height: 9,
image_url_list: ['https://example.com/image.jpg']
}
多图组合示例
单次请求最多可组合 9 张图像:
{
model_name: 'wan-v2.7-image-edit',
prompt: 'Combine these images into a cohesive landscape',
width: 16,
height: 9,
image_url_list: [
'https://example.com/image1.jpg',
'https://example.com/image2.jpg',
'https://example.com/image3.jpg'
]
}
Wan 2.7 Image Pro(Text-to-Image)
使用与 Wan 2.7 Image 相同的参数,并将 model_name 设为 wan-v2.7-image-pro 以获得增强输出质量。
示例请求
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: 'wan-v2.7-image-pro',
prompt: 'A professional product photo with studio lighting',
width: 16,
height: 9
})
});
const { data } = await response.json();
const taskId = data.task_id;
Wan 2.7 Image Pro Edit(Image Editing)
使用与 Wan 2.7 Image Edit 相同的参数,并将 model_name 设为 wan-v2.7-image-pro-edit 以获得增强输出质量。
示例请求
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: 'wan-v2.7-image-pro-edit',
prompt: 'Replace the background with a modern office interior',
width: 16,
height: 9,
image_url_list: ['https://example.com/image.jpg']
})
});
const { data } = await response.json();
const taskId = data.task_id;
响应格式
初始响应
所有模型都会返回用于轮询的 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"
}
轮询响应
轮询 GET /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.0997,
"images": [
{
"url": "https://example.com/generated-image.jpeg"
}
]
}
},
"message": "success"
}
状态值
submitted:任务已接受
processing:生成处理中
succeed:生成已成功完成
failed:生成失败
错误处理
常见错误
无效宽高比
{
"code": 400,
"message": "Ratio must be one of: 16:9, 9:16, 1:1, 4:3, 3:4, 3:2, 2:3"
}
缺少图像 URL(Edit 模式)
{
"code": 400,
"message": "image_url_list is required for edit models"
}
图像数量过多(Edit 模式)
{
"code": 400,
"message": "image_url_list supports a maximum of 9 images"
}
Unauthorized
{
"code": 401,
"message": "Invalid or missing API key"
}
最佳实践
Text-to-Image 提示
- 具体明确:在 prompt 中包含主体、风格、光照和构图细节
- 宽高比选择:根据使用场景选择比例(16:9 用于网页横幅,9:16 用于移动端,1:1 用于社交媒体)
- 使用 Seed 复现结果:当你需要在多次请求中获得一致结果时,设置固定的
seed 值
- Standard vs Pro:高吞吐工作流使用 Standard;输出质量优先时使用 Pro
图像编辑提示
- 清晰指令:在 prompt 中具体说明要修改的内容
- 多图组合:提供最多 9 张图像,并描述应如何组合
- Prompt 引导:描述期望结果,而不只是列出修改项
- 图像质量:质量更高的输入图像通常会产生更好的编辑结果