Wan 2.7 Image Generation & Editing
Validation
mkdir -p output/aliyun-wan-image
python -m py_compile skills/ai/image/aliyun-wan-image/scripts/generate_image.py && echo "py_compile_ok" > output/aliyun-wan-image/validate.txt
Pass criteria: command exits 0 and output/aliyun-wan-image/validate.txt is generated.
Output And Evidence
- Write generated image URLs, prompts, and metadata to
output/aliyun-wan-image/.
- Keep at least one sample JSON response per run.
Prerequisites
- Install SDK (recommended in a venv):
python3 -m venv .venv
. .venv/bin/activate
python -m pip install dashscope
- Set
DASHSCOPE_API_KEY in your environment, or add dashscope_api_key to ~/.alibabacloud/credentials.
Critical model names
wan2.7-image-pro — professional version, supports 4K output
wan2.7-image — faster generation, up to 2K
Capabilities
| Capability |
Description |
| Text-to-image |
Generate images from text prompts |
| Image editing |
Edit images with text instructions (1-9 input images) |
| Interactive editing |
Edit specific regions via bounding boxes (bbox_list) |
| Group generation |
Generate consistent multi-image sequences (enable_sequential=true, up to 12 images) |
| Color palette |
Control color theme with custom hex+ratio palette (3-10 colors) |
| Thinking mode |
Enhanced reasoning for better quality (text-to-image only) |
API endpoint
Sync (recommended):
POST https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation
Async (for long tasks):
POST https://dashscope.aliyuncs.com/api/v1/services/aigc/image-generation/generation
Header: X-DashScope-Async: enable
Normalized interface (image.generate)
Request
prompt (string, required) — up to 5000 characters
size (string, optional) — 1K, 2K (default), 4K (pro only), or WxH pixel values
n (int, optional) — number of images, 1-4 (default 4), or 1-12 with enable_sequential
seed (int, optional) — range [0, 2147483647]
reference_image (string/array, optional) — URL or base64, up to 9 images
enable_sequential (bool, optional) — group image generation mode
thinking_mode (bool, optional, default true) — enhanced reasoning (text-to-image only)
bbox_list (array, optional) — bounding boxes for interactive editing
color_palette (array, optional) — custom color theme (3-10 colors with hex+ratio)
watermark (bool, optional, default false)
Response
image_url (string) — PNG, valid for 24 hours
image_count (int)
size (string) — actual output resolution
seed (int)
Quick start (Python + DashScope SDK)
import os
from dashscope.aigc.image_generation import ImageGeneration
def generate_image(req: dict) -> dict:
messages = [
{
"role": "user",
"content": [{"text": req["prompt"]}],
}
]
# Add reference images if provided
ref_images = req.get("reference_images") or []
if req.get("reference_image"):
ref_images = [req["reference_image"]] + ref_images
for img in ref_images:
messages[0]["content"].append({"image": img})
params = {
"model": req.get("model", "wan2.7-image"),
"messages": messages,
"size": req.get("size", "2K"),
"n": req.get("n", 1),
"api_key": os.getenv("DASHSCOPE_API_KEY"),
"seed": req.get("seed"),
"watermark": req.get("watermark", False),
}
if req.get("enable_sequential"):
params["enable_sequential"] = True
if req.get("thinking_mode") is not None:
params["thinking_mode"] = req["thinking_mode"]
if req.get("bbox_list"):
params["bbox_list"] = req["bbox_list"]
if req.get("color_palette"):
params["color_palette"] = req["color_palette"]
response = ImageGeneration.call(**params)
content = response.output["choices"][0]["message"]["content"]
images = [item["image"] for item in content if isinstance(item, dict) and item.get("image")]
return {
"image_urls": images,
"image_count": response.usage.get("image_count"),
"size": response.usage.get("size"),
}
Size reference
| Model |
Supported sizes |
Default |
| wan2.7-image-pro |
1K, 2K, 4K (text-to-image only), or [768, 4096] px |
2K |
| wan2.7-image |
1K, 2K, or [768, 2048] px |
2K |
Error handling
| Error |
Likely cause |
Action |
| 401/403 |
Missing or invalid DASHSCOPE_API_KEY |
Check env var or credentials file. |
400 InvalidParameter |
Unsupported size, bad n value, or missing required image |
Validate parameters against model limits. |
| 429 |
Rate limit or quota |
Retry with backoff. |
Output location
- Default output:
output/aliyun-wan-image/images/
- Override base dir with
OUTPUT_DIR.
Anti-patterns
- Do not invent model names; use
wan2.7-image or wan2.7-image-pro only.
- Do not use 4K size with
wan2.7-image (only pro supports 4K).
- Do not use
enable_sequential with bbox_list — they are separate modes.
- Image URLs expire after 24 hours; download and persist immediately.
Workflow
- Confirm user intent: text-to-image, image editing, group generation, or interactive editing.
- Select appropriate model (pro for 4K or higher quality, standard for speed).
- Execute with explicit parameters and bounded scope.
- Download and save generated images before URL expiration.
References
- See
references/api_reference.md for full HTTP API details.
- See
references/sources.md for source links.
1---2name: aliyun-wan-image3description: Use 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-generation API.4---5
6# Wan 2.7 Image Generation & Editing
7
8## Validation
9
10```bash
11mkdir -p output/aliyun-wan-image
12python -m py_compile skills/ai/image/aliyun-wan-image/scripts/generate_image.py && echo "py_compile_ok" > output/aliyun-wan-image/validate.txt
13```
14
15Pass criteria: command exits 0 and `output/aliyun-wan-image/validate.txt` is generated.
16
17## Output And Evidence
18
19- Write generated image URLs, prompts, and metadata to `output/aliyun-wan-image/`.
20- Keep at least one sample JSON response per run.
21
22## Prerequisites
23
24- Install SDK (recommended in a venv):
25
26```bash
27python3 -m venv .venv
28. .venv/bin/activate
29python -m pip install dashscope
30```
31- Set `DASHSCOPE_API_KEY` in your environment, or add `dashscope_api_key` to `~/.alibabacloud/credentials`.
32
33## Critical model names
34
35- `wan2.7-image-pro` — professional version, supports 4K output
36- `wan2.7-image` — faster generation, up to 2K
37
38## Capabilities
39
40| Capability | Description |
41|---|---|
42| Text-to-image | Generate images from text prompts |
43| Image editing | Edit images with text instructions (1-9 input images) |
44| Interactive editing | Edit specific regions via bounding boxes (`bbox_list`) |
45| Group generation | Generate consistent multi-image sequences (`enable_sequential=true`, up to 12 images) |
46| Color palette | Control color theme with custom hex+ratio palette (3-10 colors) |
47| Thinking mode | Enhanced reasoning for better quality (text-to-image only) |
48
49## API endpoint
50
51**Sync (recommended):**
52```
53POST https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation
54```
55
56**Async (for long tasks):**
57```
58POST https://dashscope.aliyuncs.com/api/v1/services/aigc/image-generation/generation
59Header: X-DashScope-Async: enable
60```
61
62## Normalized interface (image.generate)
63
64### Request
65- `prompt` (string, required) — up to 5000 characters
66- `size` (string, optional) — `1K`, `2K` (default), `4K` (pro only), or `WxH` pixel values
67- `n` (int, optional) — number of images, 1-4 (default 4), or 1-12 with `enable_sequential`
68- `seed` (int, optional) — range [0, 2147483647]
69- `reference_image` (string/array, optional) — URL or base64, up to 9 images
70- `enable_sequential` (bool, optional) — group image generation mode
71- `thinking_mode` (bool, optional, default true) — enhanced reasoning (text-to-image only)
72- `bbox_list` (array, optional) — bounding boxes for interactive editing
73- `color_palette` (array, optional) — custom color theme (3-10 colors with hex+ratio)
74- `watermark` (bool, optional, default false)
75
76### Response
77- `image_url` (string) — PNG, valid for 24 hours
78- `image_count` (int)
79- `size` (string) — actual output resolution
80- `seed` (int)
81
82## Quick start (Python + DashScope SDK)
83
84```python
85import os
86from dashscope.aigc.image_generation import ImageGeneration
87
88def generate_image(req: dict) -> dict:
89 messages = [
90 {
91 "role": "user",
92 "content": [{"text": req["prompt"]}],
93 }
94 ]
95
96 # Add reference images if provided
97 ref_images = req.get("reference_images") or []
98 if req.get("reference_image"):
99 ref_images = [req["reference_image"]] + ref_images
100 for img in ref_images:
101 messages[0]["content"].append({"image": img})
102
103 params = {
104 "model": req.get("model", "wan2.7-image"),
105 "messages": messages,
106 "size": req.get("size", "2K"),
107 "n": req.get("n", 1),
108 "api_key": os.getenv("DASHSCOPE_API_KEY"),
109 "seed": req.get("seed"),
110 "watermark": req.get("watermark", False),
111 }
112
113 if req.get("enable_sequential"):
114 params["enable_sequential"] = True
115 if req.get("thinking_mode") is not None:
116 params["thinking_mode"] = req["thinking_mode"]
117 if req.get("bbox_list"):
118 params["bbox_list"] = req["bbox_list"]
119 if req.get("color_palette"):
120 params["color_palette"] = req["color_palette"]
121
122 response = ImageGeneration.call(**params)
123
124 content = response.output["choices"][0]["message"]["content"]
125 images = [item["image"] for item in content if isinstance(item, dict) and item.get("image")]
126
127 return {
128 "image_urls": images,
129 "image_count": response.usage.get("image_count"),
130 "size": response.usage.get("size"),
131 }
132```
133
134## Size reference
135
136| Model | Supported sizes | Default |
137|---|---|---|
138| wan2.7-image-pro | 1K, 2K, 4K (text-to-image only), or [768, 4096] px | 2K |
139| wan2.7-image | 1K, 2K, or [768, 2048] px | 2K |
140
141## Error handling
142
143| Error | Likely cause | Action |
144|---|---|---|
145| 401/403 | Missing or invalid `DASHSCOPE_API_KEY` | Check env var or credentials file. |
146| 400 `InvalidParameter` | Unsupported size, bad n value, or missing required image | Validate parameters against model limits. |
147| 429 | Rate limit or quota | Retry with backoff. |
148
149## Output location
150
151- Default output: `output/aliyun-wan-image/images/`
152- Override base dir with `OUTPUT_DIR`.
153
154## Anti-patterns
155
156- Do not invent model names; use `wan2.7-image` or `wan2.7-image-pro` only.
157- Do not use 4K size with `wan2.7-image` (only pro supports 4K).
158- Do not use `enable_sequential` with `bbox_list` — they are separate modes.
159- Image URLs expire after 24 hours; download and persist immediately.
160
161## Workflow
162
1631) Confirm user intent: text-to-image, image editing, group generation, or interactive editing.
1642) Select appropriate model (pro for 4K or higher quality, standard for speed).
1653) Execute with explicit parameters and bounded scope.
1664) Download and save generated images before URL expiration.
167
168## References
169
170- See `references/api_reference.md` for full HTTP API details.
171- See `references/sources.md` for source links.