$npx -y skills add cinience/alicloud-skills --skill aliyun-wan-imageUse when generating or editing images with DashScope Wan 2.7 image models (wan2.7-image, wan2.7-image-pro). Use when implementing text-to-image, image editing, interactive editing with bounding boxes, sequential group image generation, or color palette control via the multimodal-
| 1 | # Wan 2.7 Image Generation & Editing |
| 2 | |
| 3 | ## Validation |
| 4 | |
| 5 | ```bash |
| 6 | mkdir -p output/aliyun-wan-image |
| 7 | python -m py_compile skills/ai/image/aliyun-wan-image/scripts/generate_image.py && echo "py_compile_ok" > output/aliyun-wan-image/validate.txt |
| 8 | ``` |
| 9 | |
| 10 | Pass criteria: command exits 0 and `output/aliyun-wan-image/validate.txt` is generated. |
| 11 | |
| 12 | ## Output And Evidence |
| 13 | |
| 14 | - Write generated image URLs, prompts, and metadata to `output/aliyun-wan-image/`. |
| 15 | - Keep at least one sample JSON response per run. |
| 16 | |
| 17 | ## Prerequisites |
| 18 | |
| 19 | - Install SDK (recommended in a venv): |
| 20 | |
| 21 | ```bash |
| 22 | python3 -m venv .venv |
| 23 | . .venv/bin/activate |
| 24 | python -m pip install dashscope |
| 25 | ``` |
| 26 | - Set `DASHSCOPE_API_KEY` in your environment, or add `dashscope_api_key` to `~/.alibabacloud/credentials`. |
| 27 | |
| 28 | ## Critical model names |
| 29 | |
| 30 | - `wan2.7-image-pro` — professional version, supports 4K output |
| 31 | - `wan2.7-image` — faster generation, up to 2K |
| 32 | |
| 33 | ## Capabilities |
| 34 | |
| 35 | | Capability | Description | |
| 36 | |---|---| |
| 37 | | Text-to-image | Generate images from text prompts | |
| 38 | | Image editing | Edit images with text instructions (1-9 input images) | |
| 39 | | Interactive editing | Edit specific regions via bounding boxes (`bbox_list`) | |
| 40 | | Group generation | Generate consistent multi-image sequences (`enable_sequential=true`, up to 12 images) | |
| 41 | | Color palette | Control color theme with custom hex+ratio palette (3-10 colors) | |
| 42 | | Thinking mode | Enhanced reasoning for better quality (text-to-image only) | |
| 43 | |
| 44 | ## API endpoint |
| 45 | |
| 46 | **Sync (recommended):** |
| 47 | ``` |
| 48 | POST https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation |
| 49 | ``` |
| 50 | |
| 51 | **Async (for long tasks):** |
| 52 | ``` |
| 53 | POST https://dashscope.aliyuncs.com/api/v1/services/aigc/image-generation/generation |
| 54 | Header: X-DashScope-Async: enable |
| 55 | ``` |
| 56 | |
| 57 | ## Normalized interface (image.generate) |
| 58 | |
| 59 | ### Request |
| 60 | - `prompt` (string, required) — up to 5000 characters |
| 61 | - `size` (string, optional) — `1K`, `2K` (default), `4K` (pro only), or `WxH` pixel values |
| 62 | - `n` (int, optional) — number of images, 1-4 (default 4), or 1-12 with `enable_sequential` |
| 63 | - `seed` (int, optional) — range [0, 2147483647] |
| 64 | - `reference_image` (string/array, optional) — URL or base64, up to 9 images |
| 65 | - `enable_sequential` (bool, optional) — group image generation mode |
| 66 | - `thinking_mode` (bool, optional, default true) — enhanced reasoning (text-to-image only) |
| 67 | - `bbox_list` (array, optional) — bounding boxes for interactive editing |
| 68 | - `color_palette` (array, optional) — custom color theme (3-10 colors with hex+ratio) |
| 69 | - `watermark` (bool, optional, default false) |
| 70 | |
| 71 | ### Response |
| 72 | - `image_url` (string) — PNG, valid for 24 hours |
| 73 | - `image_count` (int) |
| 74 | - `size` (string) — actual output resolution |
| 75 | - `seed` (int) |
| 76 | |
| 77 | ## Quick start (Python + DashScope SDK) |
| 78 | |
| 79 | ```python |
| 80 | import os |
| 81 | from dashscope.aigc.image_generation import ImageGeneration |
| 82 | |
| 83 | def generate_image(req: dict) -> dict: |
| 84 | messages = [ |
| 85 | { |
| 86 | "role": "user", |
| 87 | "content": [{"text": req["prompt"]}], |
| 88 | } |
| 89 | ] |
| 90 | |
| 91 | # Add reference images if provided |
| 92 | ref_images = req.get("reference_images") or [] |
| 93 | if req.get("reference_image"): |
| 94 | ref_images = [req["reference_image"]] + ref_images |
| 95 | for img in ref_images: |
| 96 | messages[0]["content"].append({"image": img}) |
| 97 | |
| 98 | params = { |
| 99 | "model": req.get("model", "wan2.7-image"), |
| 100 | "messages": messages, |
| 101 | "size": req.get("size", "2K"), |
| 102 | "n": req.get("n", 1), |
| 103 | "api_key": os.getenv("DASHSCOPE_API_KEY"), |
| 104 | "seed": req.get("seed"), |
| 105 | "watermark": req.get("watermark", False), |
| 106 | } |
| 107 | |
| 108 | if req.get("enable_sequential"): |
| 109 | params["enable_sequential"] = True |
| 110 | if req.get("thinking_mode") is not None: |
| 111 | params["thinking_mode"] = req["thinking_mode"] |
| 112 | if req.get("bbox_list"): |
| 113 | params["bbox_list"] = req["bbox_list"] |
| 114 | if req.get("color_palette"): |
| 115 | params["color_palette"] = req["color_palette"] |
| 116 | |
| 117 | response = ImageGeneration.call(**params) |
| 118 | |
| 119 | content = response.output["choices"][0]["message"]["content"] |
| 120 | images = [item["image"] for item in content if isinstance(item, dict) and item.get("image")] |
| 121 | |
| 122 | return { |
| 123 | "image_urls": images, |
| 124 | "image_count": response.usage.get("image_count"), |
| 125 | "size": response.usage.get("size"), |
| 126 | } |
| 127 | ``` |
| 128 | |
| 129 | ## Size reference |
| 130 | |
| 131 | | Model | Supported sizes | Default | |
| 132 | |---|---|---| |
| 133 | | wan2.7-image-pro | 1K, 2K, 4K (text-to-image only), or [768, 4096] px | 2K | |
| 134 | | wan2.7-image | 1K, 2K, or [768, 2048] px | 2K | |
| 135 | |
| 136 | ## Error handling |
| 137 | |
| 138 | | Error | Likely cause | Action | |
| 139 | |---|---|---| |
| 140 | | 401/403 | Missing or invalid `DASHSCOPE_API_KEY` | Check env var or credentials file. | |
| 141 | | 400 `InvalidParameter` | Unsupported size, bad n value, or missing required image | Valida |