alicloud-ai-video-wan-video
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCategory: provider
分类:供应商
Model Studio Wan Video
Model Studio Wan Video
Provide consistent video generation behavior for the video-agent pipeline by standardizing inputs/outputs and using DashScope SDK (Python) with the exact model name.
video.generate通过标准化的输入/输出,并使用指定模型名称的DashScope SDK(Python版),为video-agent工作流提供一致的视频生成行为。
video.generateCritical model name
重要模型名称
Use ONLY this exact model string:
wan2.6-i2v-flash
Do not add date suffixes or aliases.
只能使用以下精确模型字符串:
wan2.6-i2v-flash
请勿添加日期后缀或别名。
Prerequisites
前置条件
- Install SDK (recommended in a venv to avoid PEP 668 limits):
bash
python3 -m venv .venv
. .venv/bin/activate
python -m pip install dashscope- Set in your environment, or add
DASHSCOPE_API_KEYtodashscope_api_key(env takes precedence).~/.alibabacloud/credentials
- 安装SDK(建议在虚拟环境中安装以避免PEP 668限制):
bash
python3 -m venv .venv
. .venv/bin/activate
python -m pip install dashscope- 在环境变量中设置,或在
DASHSCOPE_API_KEY中添加~/.alibabacloud/credentials(环境变量优先级更高)。dashscope_api_key
Normalized interface (video.generate)
标准化接口(video.generate)
Request
请求参数
- (string, required)
prompt - (string, optional)
negative_prompt - (number, required) seconds
duration - (number, required)
fps - (string, required) e.g.
size1280*720 - (int, optional)
seed - (string | bytes, required for
reference_image)wan2.6-i2v-flash - (number, optional)
motion_strength
- (字符串,必填)
prompt - (字符串,可选)
negative_prompt - (数字,必填)秒
duration - (数字,必填)
fps - (字符串,必填)例如
size1280*720 - (整数,可选)
seed - (字符串 | 字节,
reference_image模型必填)wan2.6-i2v-flash - (数字,可选)
motion_strength
Response
响应参数
- (string)
video_url - (number)
duration - (number)
fps - (int)
seed
- (字符串)
video_url - (数字)
duration - (数字)
fps - (整数)
seed
Quick start (Python + DashScope SDK)
快速开始(Python + DashScope SDK)
Video generation is usually asynchronous. Expect a task ID and poll until completion.
Note: requires an input image; map to .
wan2.6-i2v-flashreference_imageimg_urlpython
import os
from dashscope import VideoSynthesis视频生成通常为异步操作。会返回任务ID,需轮询直至任务完成。
注意:模型需要输入图片;需将映射至参数。
wan2.6-i2v-flashreference_imageimg_urlpython
import os
from dashscope import VideoSynthesisPrefer env var for auth: export DASHSCOPE_API_KEY=...
Prefer env var for auth: export DASHSCOPE_API_KEY=...
Or use ~/.alibabacloud/credentials with dashscope_api_key under [default].
Or use ~/.alibabacloud/credentials with dashscope_api_key under [default].
def generate_video(req: dict) -> dict:
payload = {
"model": "wan2.6-i2v-flash",
"prompt": req["prompt"],
"negative_prompt": req.get("negative_prompt"),
"duration": req.get("duration", 4),
"fps": req.get("fps", 24),
"size": req.get("size", "1280*720"),
"seed": req.get("seed"),
"motion_strength": req.get("motion_strength"),
"api_key": os.getenv("DASHSCOPE_API_KEY"),
}
if req.get("reference_image"):
# DashScope expects img_url for i2v models; local files are auto-uploaded.
payload["img_url"] = req["reference_image"]
response = VideoSynthesis.call(**payload)
# Some SDK versions require polling for the final result.
# If a task_id is returned, poll until status is SUCCEEDED.
result = response.output.get("results", [None])[0]
return {
"video_url": None if not result else result.get("url"),
"duration": response.output.get("duration"),
"fps": response.output.get("fps"),
"seed": response.output.get("seed"),
}undefineddef generate_video(req: dict) -> dict:
payload = {
"model": "wan2.6-i2v-flash",
"prompt": req["prompt"],
"negative_prompt": req.get("negative_prompt"),
"duration": req.get("duration", 4),
"fps": req.get("fps", 24),
"size": req.get("size", "1280*720"),
"seed": req.get("seed"),
"motion_strength": req.get("motion_strength"),
"api_key": os.getenv("DASHSCOPE_API_KEY"),
}
if req.get("reference_image"):
# DashScope expects img_url for i2v models; local files are auto-uploaded.
payload["img_url"] = req["reference_image"]
response = VideoSynthesis.call(**payload)
# Some SDK versions require polling for the final result.
# If a task_id is returned, poll until status is SUCCEEDED.
result = response.output.get("results", [None])[0]
return {
"video_url": None if not result else result.get("url"),
"duration": response.output.get("duration"),
"fps": response.output.get("fps"),
"seed": response.output.get("seed"),
}undefinedAsync handling (polling)
异步处理(轮询方式)
python
import os
from dashscope import VideoSynthesis
task = VideoSynthesis.async_call(
model="wan2.6-i2v-flash",
prompt=req["prompt"],
img_url=req["reference_image"],
duration=req.get("duration", 4),
fps=req.get("fps", 24),
size=req.get("size", "1280*720"),
api_key=os.getenv("DASHSCOPE_API_KEY"),
)
final = VideoSynthesis.wait(task)
video_url = final.output.get("video_url")python
import os
from dashscope import VideoSynthesis
task = VideoSynthesis.async_call(
model="wan2.6-i2v-flash",
prompt=req["prompt"],
img_url=req["reference_image"],
duration=req.get("duration", 4),
fps=req.get("fps", 24),
size=req.get("size", "1280*720"),
api_key=os.getenv("DASHSCOPE_API_KEY"),
)
final = VideoSynthesis.wait(task)
video_url = final.output.get("video_url")Operational guidance
操作指南
- Video generation can take minutes; expose progress and allow cancel/retry.
- Cache by .
(prompt, negative_prompt, duration, fps, size, seed, reference_image hash, motion_strength) - Store video assets in object storage and persist only URLs in metadata.
- can be a URL or local path; the SDK auto-uploads local files.
reference_image - If you get , the reference image is missing or not mapped.
Field required: input.img_url
- 视频生成可能需要数分钟时间;需展示进度并支持取消/重试。
- 按进行缓存。
(prompt, negative_prompt, duration, fps, size, seed, reference_image哈希值, motion_strength) - 将视频资产存储至对象存储服务,仅在元数据中保留URL。
- 可以是URL或本地路径;SDK会自动上传本地文件。
reference_image - 若收到错误,说明参考图片缺失或未正确映射。
Field required: input.img_url
Size notes
尺寸说明
- Use format (e.g.
WxH).1280*720 - Prefer common sizes; unsupported sizes can return 400.
- 使用格式(例如
宽*高)。1280*720 - 优先使用常见尺寸;不支持的尺寸会返回400错误。
Output location
输出位置
- Default output:
output/ai-video-wan-video/videos/ - Override base dir with .
OUTPUT_DIR
- 默认输出路径:
output/ai-video-wan-video/videos/ - 可通过环境变量修改基础目录。
OUTPUT_DIR
Anti-patterns
反模式
- Do not invent model names or aliases; use only.
wan2.6-i2v-flash - Do not block the UI without progress updates.
- Do not retry blindly on 4xx; handle validation failures explicitly.
- 请勿自行创建模型名称或别名;仅使用。
wan2.6-i2v-flash - 请勿在无进度更新的情况下阻塞UI。
- 请勿在收到4xx错误时盲目重试;需显式处理验证失败。
References
参考资料
-
Seefor DashScope SDK mapping and async handling notes.
references/api_reference.md -
Source list:
references/sources.md
-
有关DashScope SDK映射及异步处理说明,请查看。
references/api_reference.md -
来源列表:
references/sources.md