# Qwen Image 2.0 API Complete API reference for Qwen Image 2.0 models powered by Alibaba Qwen. ## Model Variants This API supports four model variants: | Model | ID | Description | |-------|-----|-------------| | **Qwen Image 2** | `qwen-image-2.0` | Text-to-image generation | | **Qwen Image 2 Edit** | `qwen-image-2.0-edit` | Image editing and multi-image composition | | **Qwen Image 2 Pro** | `qwen-image-2.0-pro` | Enhanced text-to-image generation with higher quality output | | **Qwen Image 2 Pro Edit** | `qwen-image-2.0-pro-edit` | Enhanced image editing and multi-image composition | ## Quick Comparison | Feature | Standard | Pro | |---------|----------|-----| | Text-to-Image | ✅ Yes | ✅ Yes | | Image Editing | ✅ Yes | ✅ Yes | | Aspect Ratios | 7 options | 7 options | | Image Input (Edit) | ✅ Yes (1-6 images) | ✅ Yes (1-6 images) | | Multi-Image Support | ✅ Yes | ✅ Yes | | Output Quality | Standard | Enhanced | | Feature | Text-to-Image | Edit | |---------|---------------|------| | Input | Text prompt | Image(s) + Text prompt | | Image Input | ❌ No | ✅ Yes (1-6 images) | | Multi-Image Support | ❌ No | ✅ Yes | | Seed Support | ✅ Optional | ✅ Optional | ### Supported Aspect Ratios Both Standard and Pro models support 7 aspect ratios: - `16:9` (default), `9:16`, `1:1`, `4:3`, `3:4`, `3:2`, `2:3` ## Qwen Image 2 (Text-to-Image) ### Endpoint ``` POST /api/v1/image/task ``` ### Authentication ``` Authorization: Bearer YOUR_API_KEY ``` ### Request Parameters #### Required | Parameter | Type | Description | |-----------|------|-------------| | `model_name` | string | Must be `"qwen-image-2.0"` | | `prompt` | string | Image generation prompt | | `width` | number | Width ratio value (e.g., 16 for 16:9) | | `height` | number | Height ratio value (e.g., 9 for 16:9) | **Note:** The width:height ratio must be one of: `16:9`, `9:16`, `1:1`, `4:3`, `3:4`, `3:2`, `2:3` #### Optional | Parameter | Type | Description | |-----------|------|-------------| | `seed` | number | Random seed for reproducible results | ### Example Request ```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 (Image Editing) ### Endpoint ``` POST /api/v1/image/task ``` ### Request Parameters #### Required | Parameter | Type | Description | |-----------|------|-------------| | `model_name` | string | Must be `"qwen-image-2.0-edit"` | | `prompt` | string | Description of desired edits | | `width` | number | Width ratio value (e.g., 16 for 16:9) | | `height` | number | Height ratio value (e.g., 9 for 16:9) | | `image_url_list` | string[] | Array of input image URLs (1-6 items) | **Note:** The width:height ratio must be one of: `16:9`, `9:16`, `1:1`, `4:3`, `3:4`, `3:2`, `2:3` #### Optional | Parameter | Type | Description | |-----------|------|-------------| | `seed` | number | Random seed for reproducible results | ### Single Image Edit Example ```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'] } ``` ### Multi-Image Composition Example Up to 6 images can be combined in a single request: ```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 (Text-to-Image) Uses the same parameters as Qwen Image 2, with `model_name` set to `qwen-image-2.0-pro` for enhanced output quality. ### Example Request ```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 (Image Editing) Uses the same parameters as Qwen Image 2 Edit, with `model_name` set to `qwen-image-2.0-pro-edit` for enhanced output quality. ### Example Request ```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; ``` ## Response Format ### Initial Response All models return a `task_id` for polling: ```json { "code": 0, "data": { "task_id": "{task_id}", "task_status": "submitted", "response_url": "https://api.flaq.ai/api/v1/image/{task_id}" }, "message": "success" } ``` ### Polling Response Poll `GET /api/v1/image/{taskId}` to check status: ```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" } ``` ### Status Values - `submitted`: Task accepted - `processing`: Generation in progress - `succeed`: Generation completed successfully - `failed`: Generation failed ## Error Handling ### Common Errors **Invalid Aspect Ratio** ```json { "code": 400, "message": "Ratio must be one of: 16:9, 9:16, 1:1, 4:3, 3:4, 3:2, 2:3" } ``` **Missing Image URL (Edit Mode)** ```json { "code": 400, "message": "image_url_list is required for edit models" } ``` **Too Many Images (Edit Mode)** ```json { "code": 400, "message": "image_url_list supports a maximum of 6 images" } ``` **Unauthorized** ```json { "code": 401, "message": "Invalid or missing API key" } ``` ## Best Practices ### Text-to-Image Tips 1. **Be Specific**: Include subject, style, lighting, and composition details in your prompt 2. **Aspect Ratio Selection**: Choose ratio based on your use case (16:9 for web banners, 9:16 for mobile, 1:1 for social media) 3. **Use Seed for Reproducibility**: Set a fixed `seed` value when you need consistent results across requests 4. **Standard vs Pro**: Use Standard for rapid iteration when output quality is the priority ### Image Editing Tips 1. **Clear Instructions**: Be specific about what to change in the prompt 2. **Multi-Image Composition**: Provide up to 6 images and describe how they should be combined 3. **Prompt Guidance**: Describe the desired outcome rather than just listing changes 4. **Image Quality**: Higher quality input images generally produce better editing results