# 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. **圖像品質**:更高品質的輸入圖像通常会产生更好的編輯結果