$npx -y skills add cinience/alicloud-skills --skill aliyun-wan-videoUse when generating videos with Model Studio DashScope SDK using Wan video generation models (wan2.6-t2v, wan2.6-i2v-flash, wan2.6-i2v and regional variants). Use when implementing or documenting video.generate requests/responses, mapping prompt/negative_prompt/duration/fps/size/
| 1 | Category: provider |
| 2 | |
| 3 | # Model Studio Wan Video |
| 4 | |
| 5 | ## Validation |
| 6 | |
| 7 | ```bash |
| 8 | mkdir -p output/aliyun-wan-video |
| 9 | python -m py_compile skills/ai/video/aliyun-wan-video/scripts/generate_video.py && echo "py_compile_ok" > output/aliyun-wan-video/validate.txt |
| 10 | ``` |
| 11 | |
| 12 | Pass criteria: command exits 0 and `output/aliyun-wan-video/validate.txt` is generated. |
| 13 | |
| 14 | ## Output And Evidence |
| 15 | |
| 16 | - Save task IDs, polling responses, and final video URLs to `output/aliyun-wan-video/`. |
| 17 | - Keep one end-to-end run log for troubleshooting. |
| 18 | |
| 19 | Provide consistent video generation behavior for the video-agent pipeline by standardizing `video.generate` inputs/outputs and using DashScope SDK (Python) with the exact model name. |
| 20 | |
| 21 | ## Critical model names |
| 22 | |
| 23 | Use one of these exact model strings: |
| 24 | - `wan2.6-t2v` |
| 25 | - `wan2.6-t2v-us` |
| 26 | - `wan2.2-t2v-plus` |
| 27 | - `wan2.2-t2v-flash` |
| 28 | - `wan2.6-i2v-flash` |
| 29 | - `wan2.6-i2v` |
| 30 | - `wan2.6-i2v-us` |
| 31 | - `wanx2.1-t2v-turbo` |
| 32 | |
| 33 | ## Prerequisites |
| 34 | |
| 35 | - Install SDK (recommended in a venv to avoid PEP 668 limits): |
| 36 | |
| 37 | ```bash |
| 38 | python3 -m venv .venv |
| 39 | . .venv/bin/activate |
| 40 | python -m pip install dashscope |
| 41 | ``` |
| 42 | - Set `DASHSCOPE_API_KEY` in your environment, or add `dashscope_api_key` to `~/.alibabacloud/credentials` (env takes precedence). |
| 43 | |
| 44 | ## Normalized interface (video.generate) |
| 45 | |
| 46 | ### Request |
| 47 | - `prompt` (string, required) |
| 48 | - `negative_prompt` (string, optional) |
| 49 | - `duration` (number, required) seconds |
| 50 | - `fps` (number, required) |
| 51 | - `size` (string, required) e.g. `1280*720` |
| 52 | - `seed` (int, optional) |
| 53 | - `reference_image` (string | bytes, optional for t2v, required for i2v family models) |
| 54 | - `motion_strength` (number, optional) |
| 55 | |
| 56 | ### Response |
| 57 | - `video_url` (string) |
| 58 | - `duration` (number) |
| 59 | - `fps` (number) |
| 60 | - `seed` (int) |
| 61 | |
| 62 | ## Quick start (Python + DashScope SDK) |
| 63 | |
| 64 | Video generation is usually asynchronous. Expect a task ID and poll until completion. |
| 65 | Note: Wan i2v models require an input image; pure t2v models such as `wan2.6-t2v` can omit `reference_image`. |
| 66 | |
| 67 | ```python |
| 68 | import os |
| 69 | from dashscope import VideoSynthesis |
| 70 | |
| 71 | # Prefer env var for auth: export DASHSCOPE_API_KEY=... |
| 72 | # Or use ~/.alibabacloud/credentials with dashscope_api_key under [default]. |
| 73 | |
| 74 | def generate_video(req: dict) -> dict: |
| 75 | payload = { |
| 76 | "model": req.get("model", "wan2.6-i2v-flash"), |
| 77 | "prompt": req["prompt"], |
| 78 | "negative_prompt": req.get("negative_prompt"), |
| 79 | "duration": req.get("duration", 4), |
| 80 | "fps": req.get("fps", 24), |
| 81 | "size": req.get("size", "1280*720"), |
| 82 | "seed": req.get("seed"), |
| 83 | "motion_strength": req.get("motion_strength"), |
| 84 | "api_key": os.getenv("DASHSCOPE_API_KEY"), |
| 85 | } |
| 86 | |
| 87 | if req.get("reference_image"): |
| 88 | # DashScope expects img_url for i2v models; local files are auto-uploaded. |
| 89 | payload["img_url"] = req["reference_image"] |
| 90 | |
| 91 | response = VideoSynthesis.call(**payload) |
| 92 | |
| 93 | # Some SDK versions require polling for the final result. |
| 94 | # If a task_id is returned, poll until status is SUCCEEDED. |
| 95 | result = response.output.get("results", [None])[0] |
| 96 | |
| 97 | return { |
| 98 | "video_url": None if not result else result.get("url"), |
| 99 | "duration": response.output.get("duration"), |
| 100 | "fps": response.output.get("fps"), |
| 101 | "seed": response.output.get("seed"), |
| 102 | } |
| 103 | ``` |
| 104 | |
| 105 | ## Async handling (polling) |
| 106 | |
| 107 | ```python |
| 108 | import os |
| 109 | from dashscope import VideoSynthesis |
| 110 | |
| 111 | task = VideoSynthesis.async_call( |
| 112 | model=req.get("model", "wan2.6-i2v-flash"), |
| 113 | prompt=req["prompt"], |
| 114 | img_url=req["reference_image"], |
| 115 | duration=req.get("duration", 4), |
| 116 | fps=req.get("fps", 24), |
| 117 | size=req.get("size", "1280*720"), |
| 118 | api_key=os.getenv("DASHSCOPE_API_KEY"), |
| 119 | ) |
| 120 | |
| 121 | final = VideoSynthesis.wait(task) |
| 122 | video_url = final.output.get("video_url") |
| 123 | ``` |
| 124 | |
| 125 | ## Operational guidance |
| 126 | |
| 127 | - Video generation can take minutes; expose progress and allow cancel/retry. |
| 128 | - Cache by `(prompt, negative_prompt, duration, fps, size, seed, reference_image hash, motion_strength)`. |
| 129 | - Store video assets in object storage and persist only URLs in metadata. |
| 130 | - `reference_image` can be a URL or local path; the SDK auto-uploads local files. |
| 131 | - If you get `Field required: input.img_url`, the reference image is missing or not mapped. |
| 132 | - `wan2.6-t2v` and `wan2.6-t2v-us` add multi-shot narrative support and optional audio input according to the official docs. |
| 133 | |
| 134 | ## Size notes |
| 135 | |
| 136 | - Use `WxH` format (e.g. `1280*720`). |
| 137 | - Prefer common sizes; unsupported sizes can return 400. |
| 138 | |
| 139 | ## Output location |
| 140 | |
| 141 | - Default output: `output/aliyun-wan-video/videos/` |
| 142 | - Override base dir with `OUTPUT_DIR`. |
| 143 | |
| 144 | ## Anti-patterns |
| 145 | |
| 146 | - Do not invent model names or aliases; use official Wan i2v model I |