# Qwen Image 2.0 API 由阿里巴巴 Qwen 提供支持的 Qwen Image 2.0 模型完整 API 参考。 ## 模型变体 此 API 支持四种模型变体: | 模型 | ID | 描述 | |-------|-----|-------------| | **Qwen Image 2** | `qwen-image-2.0` | 文本生成图像 | | **Qwen Image 2 Edit** | `qwen-image-2.0-edit` | 图像编辑和多图像合成 | | **Qwen Image 2 Pro** | `qwen-image-2.0-pro` | 增强的文本生成图像,输出质量更高 | | **Qwen Image 2 Pro Edit** | `qwen-image-2.0-pro-edit` | 增强的图像编辑和多图像合成 | ## 快速对比 | 功能 | Standard | Pro | |---------|----------|-----| | 文本生成图像 | ✅ 是 | ✅ 是 | | 图像编辑 | ✅ 是 | ✅ 是 | | 宽高比 | 7 种选项 | 7 种选项 | | 图像输入(编辑) | ✅ 是(1-6 张图像) | ✅ 是(1-6 张图像) | | 多图像支持 | ✅ 是 | ✅ 是 | | 输出质量 | 标准 | 增强 | | 功能 | Text-to-Image | Edit | |---------|---------------|------| | 输入 | 文本提示词 | 图像 + 文本提示词 | | 图像输入 | ❌ 否 | ✅ 是(1-6 张图像) | | 多图像支持 | ❌ 否 | ✅ 是 | | Seed 支持 | ✅ 可选 | ✅ 可选 | ### 支持的宽高比 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 ``` ### 请求参数 #### 必需 | 参数 | 类型 | 描述 | |-----------|------|-------------| | `model_name` | string | 必须为 `"qwen-image-2.0"` | | `prompt` | string | 图像生成提示词 | | `width` | number | 宽度比例值(例如 16:9 中的 16) | | `height` | number | 高度比例值(例如 16:9 中的 9) | **注意:** width:height 比例必须是以下之一:`16:9`、`9:16`、`1:1`、`4:3`、`3:4`、`3:2`、`2:3` #### 可选 | 参数 | 类型 | 描述 | |-----------|------|-------------| | `seed` | number | 用于可重现结果的随机种子 | ### 请求示例 ```javascript 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; // Poll for results 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 ``` ### 请求参数 #### 必需 | 参数 | 类型 | 描述 | |-----------|------|-------------| | `model_name` | string | 必须为 `"qwen-image-2.0-edit"` | | `prompt` | string | 所需编辑的描述 | | `width` | number | 宽度比例值(例如 16:9 中的 16) | | `height` | number | 高度比例值(例如 16:9 中的 9) | | `image_url_list` | string[] | Array of input image URLs (1-6 items) | **注意:** width:height 比例必须是以下之一:`16:9`、`9:16`、`1:1`、`4:3`、`3:4`、`3:2`、`2:3` #### 可选 | 参数 | 类型 | 描述 | |-----------|------|-------------| | `seed` | number | 用于可重现结果的随机种子 | ### 单图像编辑示例 ```javascript { 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 张图像: ```javascript { 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` 以获得增强的输出质量。 ### 请求示例 ```javascript 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` 以获得增强的输出质量。 ### 请求示例 ```javascript 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`: ```json { "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}` 以检查状态: ```json { "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`:生成失败 ## 错误处理 ### 常见错误 **无效的宽高比** ```json { "code": 400, "message": "Ratio must be one of: 16:9, 9:16, 1:1, 4:3, 3:4, 3:2, 2:3" } ``` **缺少图像 URL(编辑模式)** ```json { "code": 400, "message": "image_url_list is required for edit models" } ``` **图像过多(编辑模式)** ```json { "code": 400, "message": "image_url_list supports a maximum of 6 images" } ``` **未授权** ```json { "code": 401, "message": "Invalid or missing API key" } ``` ## 最佳实践 ### 文本生成图像提示 1. **具体明确**:在提示词中包含主题、风格、光照和构图细节 2. **宽高比选择**:根据使用场景选择比例(16:9 用于网页横幅,9:16 用于移动端,1:1 用于社交媒体) 3. **使用 Seed 实现可重现性**:当需要跨请求获得一致结果时,设置固定的 `seed` 值 4. **Standard vs Pro**:当输出质量是优先考虑因素时,使用 Standard 进行快速迭代 ### 图像编辑提示 1. **清晰的指令**:在提示词中明确说明要更改的内容 2. **多图像合成**:提供最多 6 张图像并描述它们应如何组合 3. **提示词指导**:描述期望的结果,而不仅仅是列出更改 4. **图像质量**:更高质量的输入图像通常会产生更好的编辑结果