Qwen Image 2.0 API
由阿里巴巴 Qwen 提供支持的 Qwen Image 2.0 模型完整 API 参考。
模型变体
此 API 支持四种模型变体:
快速对比
支持的宽高比
Standard 和 Pro 模型均支持 7 种宽高比:
16:9(默认)、9:16、1:1、4:3、3:4、3:2、2:3
Qwen Image 2(文本生成图像)
端点
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: 'qwen-image-2.0',
prompt: 'A serene mountain landscape 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);
Qwen Image 2 Edit(图像编辑)
端点
POST /api/v1/image/task
请求参数
必需
注意: width:height 比例必须是以下之一:16:9、9:16、1:1、4:3、3:4、3:2、2:3
可选
单图像编辑示例
{
model_name: 'qwen-image-2.0-edit',
prompt: 'Change the sky to sunset colors',
width: 16,
height: 9,
image_url_list: ['https://example.com/image.jpg']
}
多图像合成示例
单个请求中最多可以组合 6 张图像:
{
model_name: 'qwen-image-2.0-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']
}
Qwen Image 2 Pro(文本生成图像)
使用与 Qwen Image 2 相同的参数,将 model_name 设置为 qwen-image-2.0-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: 'qwen-image-2.0-pro',
prompt: 'A serene mountain landscape at sunset',
width: 16,
height: 9
})
});
const { data } = await response.json();
const taskId = data.task_id;
Qwen Image 2 Pro Edit(图像编辑)
使用与 Qwen Image 2 Edit 相同的参数,将 model_name 设置为 qwen-image-2.0-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: 'qwen-image-2.0-pro-edit',
prompt: 'Change the sky to sunset colors',
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 6 images"
}
未授权
{
"code": 401,
"message": "Invalid or missing API key"
}
最佳实践
文本生成图像提示
- 具体明确:在提示词中包含主题、风格、光照和构图细节
- 宽高比选择:根据使用场景选择比例(16:9 用于网页横幅,9:16 用于移动端,1:1 用于社交媒体)
- 使用 Seed 实现可重现性:当需要跨请求获得一致结果时,设置固定的
seed 值
- Standard vs Pro:当输出质量是优先考虑因素时,使用 Standard 进行快速迭代
图像编辑提示
- 清晰的指令:在提示词中明确说明要更改的内容
- 多图像合成:提供最多 6 张图像并描述它们应如何组合
- 提示词指导:描述期望的结果,而不仅仅是列出更改
- 图像质量:更高质量的输入图像通常会产生更好的编辑结果