Wan 2.7 Image API
由阿里巴巴提供支援的 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(文字生成圖像)
端點
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(圖像編輯)
端點
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(文字生成圖像)
使用與 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(圖像編輯)
使用與 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(編輯模式)
{
"code": 400,
"message": "image_url_list is required for edit models"
}
圖像过多(編輯模式)
{
"code": 400,
"message": "image_url_list supports a maximum of 9 images"
}
未授权
{
"code": 401,
"message": "Invalid or missing API key"
}
最佳實踐
文字生成圖像提示
- 具體明確:在提示詞中包含主题、風格、光照和构圖細節
- 長寬比選擇:根據使用場景選擇比例(16:9 用於网页横幅,9:16 用於移动端,1:1 用於社交媒体)
- 使用 Seed 实现可重现性:当需要跨請求獲得一致結果時,设置固定的
seed 值
- Standard vs Pro:高用量工作流程使用 Standard;當輸出品質優先時使用 Pro
圖像編輯提示
- 清晰的指令:在提示詞中明確說明要更改的內容
- 多圖像合成:提供最多 9 張圖像,並說明它們應如何組合
- 提示詞指导:說明期望的結果,而不僅僅是列出更改
- 圖像品質:更高品質的輸入圖像通常会产生更好的編輯結果