全部产品
Search
文档中心

大模型服务平台百炼:通义万相-文生视频API参考

更新时间:Dec 18, 2025

通义万相文生视频模型基于文本提示词,生成一段流畅的视频。支持的能力包括:

  • 基础能力:支持选择视频时长(5/10/15秒)、指定视频分辨率(480P/720P/1080P)、智能改写prompt、添加水印。

  • 音频能力:支持自动配音,或传入自定义音频文件,实现音画同步。(wan2.5、wan2.6支持)

  • 多镜头叙事:支持生成包含多个镜头的视频,在镜头切换的同时保持主体一致。(仅wan2.6支持)

快速入口:在线体验(新加坡北京通义万相官网

说明

通义万相官网的功能与API支持的能力可能存在差异。本文档以API的实际能力为准,并会随功能更新及时同步。

模型概览

输入提示词

输出视频(wan2.6,多镜头视频)

Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: 'The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them '.

前提条件

在调用前,先获取与配置 API Key,再配置API Key到环境变量。如需通过SDK进行调用,请安装DashScope SDK

重要

北京和新加坡地域拥有独立的 API Key 请求地址,不可混用,跨地域调用将导致鉴权失败或服务报错。

HTTP调用

由于文生视频任务耗时较长(通常为1-5分钟),API采用异步调用。整个流程包含 “创建任务 -> 轮询获取” 两个核心步骤,具体如下:

具体耗时受限于排队任务数和服务执行情况,请在获取结果时耐心等待。

步骤1:创建任务获取任务ID

新加坡地域POST https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis

北京地域POST https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis

说明
  • 创建成功后,使用接口返回的 task_id 查询结果,task_id 有效期为 24 小时。请勿重复创建任务,轮询获取即可。

请求参数

多镜头叙事

仅 wan2.6-t2v模型支持此功能。支持生成多镜头的视频。

# 注意:如果使用中国大陆(北京)地域的模型,需要将url替换为:https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
    -H 'X-DashScope-Async: enable' \
    -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
    -H 'Content-Type: application/json' \
    -d '{
    "model": "wan2.6-t2v",
    "input": {
        "prompt": "Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: \"The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them \"。",
        "audio_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250929/stjqnq/%E7%8B%90%E7%8B%B8.mp3"
    },
    "parameters": {
        "size": "1280*720",
        "prompt_extend": true,
        "duration": 10,
        "audio": true,
        "shot_type":"multi"
    }
}'

自动配音

仅 wan2.5 及以上版本模型支持此功能。

模型已默认开启自动配音功能,无需配置;如需显式声明,可将 parameters.audio 参数设置为 true 。

# 注意:如果使用中国大陆(北京)地域的模型,需要将url替换为:https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
    -H 'X-DashScope-Async: enable' \
    -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
    -H 'Content-Type: application/json' \
    -d '{
    "model": "wan2.5-t2v-preview",
    "input": {
        "prompt": "Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: \"The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them \""
    },
    "parameters": {
        "size": "832*480",
        "prompt_extend": true,
        "duration": 10,
        "audio": true
    }
}'

传入音频文件

仅 wan2.5 及以上版本模型支持此功能。

可通过 input.audio_url 参数传入自定义音频的 URL。

# 注意:如果使用中国大陆(北京)地域的模型,需要将url替换为:https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
    -H 'X-DashScope-Async: enable' \
    -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
    -H 'Content-Type: application/json' \
    -d '{
    "model": "wan2.5-t2v-preview",
    "input": {
        "prompt": "Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: \"The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them \"。",
        "audio_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250929/stjqnq/%E7%8B%90%E7%8B%B8.mp3"
    },
    "parameters": {
        "size": "832*480",
        "prompt_extend": true,
        "duration": 10
    }
}'

生成无声视频

参数设置因模型版本而异:

  • wan2.5 及以上版本模型:必须显式设置 parameters.audio 参数为 false

  • wan2.2 及以下版本模型:默认生成无声视频,无需设置任何参数,参考下述代码。

# 注意:如果使用华北2(北京)地域的模型,需要将url替换为:https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
    -H 'X-DashScope-Async: enable' \
    -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
    -H 'Content-Type: application/json' \
    -d '{
    "model": "wan2.2-t2v-plus",
    "input": {
        "prompt": "低对比度,在一个复古的70年代风格地铁站里,街头音乐家在昏暗的色彩和粗糙的质感中演奏。他穿着旧式夹克,手持吉他,专注地弹奏。通勤者匆匆走过,一小群人渐渐聚拢聆听。镜头慢慢向右移动,捕捉到乐器声与城市喧嚣交织的场景,背景中有老式的地铁标志和斑驳的墙面。"
    },
    "parameters": {
        "size": "832*480",
        "prompt_extend": true
    }
}'

使用反向提示词

通过 negative_prompt 排除“花朵”元素,避免其出现在视频画面中。

# 注意:如果使用华北2(北京)地域的模型,需要将url替换为:https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
    -H 'X-DashScope-Async: enable' \
    -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
    -H 'Content-Type: application/json' \
    -d '{
    "model": "wan2.2-t2v-plus",
    "input": {
        "prompt": "一只小猫在月光下奔跑",
        "negative_prompt": "花朵"
    },
    "parameters": {
        "size": "832*480"
    }
}'
请求头(Headers)

Content-Type string (必选)

请求内容类型。此参数必须设置为application/json

Authorization string(必选)

请求身份认证。接口使用阿里云百炼API-Key进行身份认证。示例值:Bearer sk-xxxx。

X-DashScope-Async string (必选)

异步处理配置参数。HTTP请求只支持异步,必须设置为enable

重要

缺少此请求头将报错:“current user api does not support synchronous calls”。

请求体(Request Body)

model string (必选)

模型名称。模型列表与价格详见模型价格

示例值:wan2.5-t2v-preview。

input object (必选)

输入的基本信息,如提示词等。

属性

prompt string (必选)

文本提示词。用来描述生成视频中期望包含的元素和视觉特点。

支持中英文,每个汉字/字母占一个字符,超过部分会自动截断。长度限制因模型版本而异:

  • wan2.6-t2v:长度不超过1500个字符。

  • wan2.5-t2v-preview:长度不超过1500个字符。

  • wan2.2及以下版本模型:长度不超过800个字符。

示例值:一只小猫在月光下奔跑。

提示词的使用技巧请参见文生视频/图生视频Prompt指南

negative_prompt string (可选)

反向提示词,用来描述不希望在视频画面中看到的内容,可以对视频画面进行限制。

支持中英文,长度不超过500个字符,超过部分会自动截断。

示例值:低分辨率、错误、最差质量、低质量、残缺、多余的手指、比例不良等。

audio_url string (可选)

支持模型:wan2.6-t2v、 wan2.5-t2v-preview。

音频文件URL,模型将使用该音频生成视频。使用方法参见设置音频参数

支持 HTTP 或 HTTPS 协议。

音频限制:

  • 格式:wav、mp3。

  • 时长:3~30s。

  • 文件大小:不超过15MB。

  • 超限处理:若音频长度超过 duration 值(5秒或10秒),自动截取前5秒或10秒,其余部分丢弃。若音频长度不足视频时长,超出音频长度部分为无声视频。例如,音频为3秒,视频时长为5秒,输出视频前3秒有声,后2秒无声。

示例值:https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/xxx.mp3。

parameters object (可选)

图像处理参数。如设置视频分辨率、开启prompt智能改写、添加水印等。

属性

size string (可选)

重要
  • size直接影响费用,费用 = 单价(基于分辨率)× 时长(秒)。同一模型:1080P > 720P > 480P,请在调用前确认模型价格

  • size必须设置为具体数值(如 1280*720),而不是 1:1或480P。

指定生成的视频分辨率,格式为宽*高。该参数的默认值和可用枚举值依赖于 model 参数,规则如下:

  • wan2.6-t2v:默认值为 1920*1080(1080P)。可选分辨率:720P、1080P对应的所有分辨率。

  • wan2.5-t2v-preview:默认值为 1920*1080(1080P)。可选分辨率:480P、720P、1080P对应的所有分辨率。

  • wan2.2-t2v-plus:默认值为 1920*1080(1080P)。可选分辨率:480P、1080P对应的所有分辨率。

  • wan2.1-t2v-turbo :默认值为 1280*720(720P)。可选分辨率:480P、720P 对应的所有分辨率。

  • wan2.1-t2v-plus:默认值为1280*720(720P)。可选分辨率:720P 对应的所有分辨率。

480P档位:可选的视频分辨率及其对应的视频宽高比为:

  • 832*480:16:9。

  • 480*832:9:16。

  • 624*624:1:1。

720P档位:可选的视频分辨率及其对应的视频宽高比为:

  • 1280*720:16:9。

  • 720*1280:9:16。

  • 960*960:1:1。

  • 1088*832:4:3。

  • 832*1088:3:4。

1080P档位:可选的视频分辨率及其对应的视频宽高比为:

  • 1920*1080: 16:9。

  • 1080*1920: 9:16。

  • 1440*1440: 1:1。

  • 1632*1248: 4:3。

  • 1248*1632: 3:4。

duration integer (可选)

重要

duration直接影响费用。费用 = 单价(基于分辨率)× 时长(秒),请在调用前确认模型价格

生成视频的时长,单位为秒。该参数的取值依赖于 model参数:

  • wan2.6-t2v:可选值为5、10、15。默认值为5。

  • wan2.5-t2v-preview:可选值为5、10。默认值为5。

  • wan2.2-t2v-plus:固定为5秒,且不支持修改。

  • wan2.1-t2v-plus:固定为5秒,且不支持修改。

  • wan2.1-t2v-turbo:固定为5秒,且不支持修改。

示例值:5。

prompt_extend boolean (可选)

是否开启prompt智能改写。开启后使用大模型对输入prompt进行智能改写。对于较短的prompt生成效果提升明显,但会增加耗时。

  • true:默认值,开启智能改写。

  • false:不开启智能改写。

示例值:true。

shot_type string (可选)

支持模型:wan2.6-t2v。

指定生成视频的镜头类型,即视频是由一个连续镜头还是多个切换镜头组成。

生效条件:仅当"prompt_extend": true 时生效。

参数优先级:shot_type > prompt。例如,若 shot_type设置为"single",即使 prompt 中包含“生成多镜头视频”,模型仍会输出单镜头视频。

可选值:

  • single:默认值,输出单镜头视频。

  • multi:输出多镜头视频。

示例值:single。

说明

当希望严格控制视频的叙事结构(如产品展示用单镜头、故事短片用多镜头),可通过此参数指定。

audio boolean (可选)

支持模型:wan2.6-t2v、 wan2.5-t2v-preview。

是否为生成的视频自动添加音频。

生效条件:仅在不传入 audio_url时生效。

参数优先级:audio_url > audio。使用方式参见设置音频参数

可选值:

  • true:默认值,表示自动添加音频,输出有声视频。

  • false:表示不添加音频,输出无声视频。

示例值:true。

说明

若希望生成纯视觉内容(如特效演示、无声动画),请显式设置 "audio": false。若需自定义配音,请使用 audio_url 而非此参数。

watermark boolean (可选)

是否添加水印标识,水印位于视频右下角,文案固定为“AI生成”。

  • false:默认值,不添加水印。

  • true:添加水印。

示例值:false。

seed integer (可选)

随机数种子,取值范围为[0, 2147483647]

未指定时,系统自动生成随机种子。若需提升生成结果的可复现性,建议固定seed值。

请注意,由于模型生成具有概率性,即使使用相同 seed,也不能保证每次生成结果完全一致。

示例值:12345。

响应参数

成功响应

请保存 task_id,用于查询任务状态与结果。

{
    "output": {
        "task_status": "PENDING",
        "task_id": "0385dc79-5ff8-4d82-bcb6-xxxxxx"
    },
    "request_id": "4909100c-7b5a-9f92-bfe5-xxxxxx"
}

异常响应

创建任务失败,请参见错误信息进行解决。

{
    "code":"InvalidApiKey",
    "message":"Invalid API-key provided.",
    "request_id":"fb53c4ec-1c12-4fc4-a580-xxxxxx"
}

output object

任务输出信息。

属性

task_id string

任务ID。查询有效期24小时。

task_status string

任务状态。

枚举值

  • PENDING:任务排队中

  • RUNNING:任务处理中

  • SUCCEEDED:任务执行成功

  • FAILED:任务执行失败

  • CANCELED:任务已取消

  • UNKNOWN:任务不存在或状态未知

request_id string

请求唯一标识。可用于请求明细溯源和问题排查。

code string

请求失败的错误码。请求成功时不会返回此参数,详情请参见错误信息

message string

请求失败的详细信息。请求成功时不会返回此参数,详情请参见错误信息

步骤2:根据任务ID查询结果

新加坡地域GET https://dashscope-intl.aliyuncs.com/api/v1/tasks/{task_id}

北京地域GET https://dashscope.aliyuncs.com/api/v1/tasks/{task_id}

说明
  • 轮询建议:视频生成过程约需数分钟,建议采用轮询机制,并设置合理的查询间隔(如 15 秒)来获取结果。

  • 任务状态流转:PENDING(排队中)→ RUNNING(处理中)→ SUCCEEDED(成功)/ FAILED(失败)。

  • 结果链接:任务成功后返回视频链接,有效期为 24 小时。建议在获取链接后立即下载并转存至永久存储(如阿里云 OSS)。

  • task_id 有效期24小时,超时后将无法查询结果,接口将返回任务状态为UNKNOWN

请求参数

查询任务结果

请将86ecf553-d340-4e21-xxxxxxxxx替换为真实的task_id。

新加坡和北京地域的API Key不同。获取与配置 API Key
以下为新加坡地域base_url,若使用北京地域的模型,需将base_url替换为https://dashscope.aliyuncs.com/api/v1/tasks/86ecf553-d340-4e21-xxxxxxxxx
curl -X GET https://dashscope-intl.aliyuncs.com/api/v1/tasks/86ecf553-d340-4e21-xxxxxxxxx \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"

请求头(Headers)

Authorization string(必选)

请求身份认证。接口使用阿里云百炼API-Key进行身份认证。示例值:Bearer sk-xxxx。

URL路径参数(Path parameters)

task_id string(必选)

任务ID。

响应参数

任务执行成功

视频URL仅保留24小时,超时后会被自动清除,请及时保存生成的视频。

{
    "request_id": "abbf7aa3-9652-4785-a622-xxxxxx",
    "output": {
        "task_id": "38513c71-5190-48e1-9f3b-xxxxxx",
        "task_status": "SUCCEEDED",
        "submit_time": "2025-09-29 14:05:22.119",
        "scheduled_time": "2025-09-29 14:05:28.278",
        "end_time": "2025-09-29 14:10:00.437",
        "orig_prompt": "Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective's office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: 'The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them '。",
        "video_url": "https://dashscope-result-sh.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx"
    },
    "usage": {
        "duration": 10,
        "size": "1280*720",
        "input_video_duration": 0,
        "output_video_duration": 10,
        "video_count": 1,
        "SR": 720
    }
}

任务执行失败

若任务执行失败,task_status将置为 FAILED,并提供错误码和信息。请参见错误信息进行解决。

{
    "request_id": "e5d70b02-ebd3-98ce-9fe8-759d7d7b107d",
    "output": {
        "task_id": "86ecf553-d340-4e21-af6e-a0c6a421c010",
        "task_status": "FAILED",
        "code": "InvalidParameter",
        "message": "The size is not match xxxxxx"
    }
}

任务查询过期

task_id查询有效期为 24 小时,超时后将无法查询,返回以下报错信息。

{
    "request_id": "a4de7c32-7057-9f82-8581-xxxxxx",
    "output": {
        "task_id": "502a00b1-19d9-4839-a82f-xxxxxx",
        "task_status": "UNKNOWN"
    }
}

output object

任务输出信息。

属性

task_id string(必选)

任务ID。

task_status string

任务状态。

枚举值

  • PENDING:任务排队中

  • RUNNING:任务处理中

  • SUCCEEDED:任务执行成功

  • FAILED:任务执行失败

  • CANCELED:任务已取消

  • UNKNOWN:任务不存在或状态未知

submit_time string

任务提交时间。时区为UTC+8,格式为 YYYY-MM-DD HH:mm:ss.SSS。

scheduled_time string

任务执行时间。时区为UTC+8,格式为 YYYY-MM-DD HH:mm:ss.SSS。

end_time string

任务完成时间。时区为UTC+8,格式为 YYYY-MM-DD HH:mm:ss.SSS。

video_url string

视频URL。仅在 task_status 为 SUCCEEDED 时返回。

链接有效期24小时,可通过此URL下载视频。视频格式为MP4(H.264 编码)。

orig_prompt string

原始输入的prompt,对应请求参数prompt

actual_prompt string

prompt_extend=true 时,系统会对输入 prompt 进行智能改写,此字段返回实际用于生成的优化后 prompt。

  • prompt_extend=false,该字段不会返回。

  • 注意:wan2.6 模型无论 prompt_extend 取值如何,均不返回此字段。

code string

请求失败的错误码。请求成功时不会返回此参数,详情请参见错误信息

message string

请求失败的详细信息。请求成功时不会返回此参数,详情请参见错误信息

usage object

输出信息统计。只对成功的结果计数。

属性

video_duration integer

仅在使用 wan2.5 及以下版本模型时返回,用于计费。

生成视频的时长,单位秒。枚举值为5、10。

input_video_duration integer

仅在使用 wan2.6 模型时返回。固定为0。

output_video_duration integer

仅在使用 wan2.6 模型时返回。

输出视频的时长,单位秒。其值等同于input.duration的值。

duration float

仅在使用 wan2.6 模型时返回,用于计费。

表示总的视频时长,且duration=input_video_duration+output_video_duration

SR integer

仅在使用 wan2.6 模型时返回。生成视频的分辨率档位。示例值:720。

video_ratio string

生成视频的分辨率。其值等同于parameters.size的值。

格式为“宽*高,示例值:1920*1080。

video_count integer

生成视频的数量。固定为1。

request_id string

请求唯一标识。可用于请求明细溯源和问题排查。

DashScope SDK调用

SDK 的参数命名与HTTP接口基本一致,参数结构根据语言特性进行封装。

由于文生视频任务耗时较长(通常为1-5分钟),SDK 在底层封装了 HTTP 异步调用流程,支持同步、异步两种调用方式。

具体耗时受限于排队任务数和服务执行情况,请在获取结果时耐心等待。

Python SDK调用

重要
  • wan2.6-t2v模型暂不支持SDK调用。

  • 请确保 DashScope Python SDK 版本不低于 1.25.2,再运行以下代码。

    若版本过低,可能会触发 “url error, please check url!” 等错误。请参考安装SDK进行更新。

同步调用

请求示例
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
import os

# 如果使用华北2(北京)地域的模型,需要将url替换为:https://dashscope.aliyuncs.com/api/v1
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'

# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
# 新加坡和北京地域的API Key不同。获取API Key:https://www.alibabacloud.com/help/zh/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY")

def sample_sync_call_t2v():
    # call sync api, will return the result
    print('please wait...')
    rsp = VideoSynthesis.call(api_key=api_key,
                              model='wan2.5-t2v-preview',
                              prompt="Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: 'The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them '.",
                              audio_url='https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250929/stjqnq/%E7%8B%90%E7%8B%B8.mp3',
                              size='832*480',
                              duration=10,
                              negative_prompt="",
                              # audio=True,
                              prompt_extend=True,
                              watermark=False,
                              seed=12345)
    print(rsp)
    if rsp.status_code == HTTPStatus.OK:
        print(rsp.output.video_url)
    else:
        print('Failed, status_code: %s, code: %s, message: %s' %
              (rsp.status_code, rsp.code, rsp.message))


if __name__ == '__main__':
    sample_sync_call_t2v()
响应示例
video_url 有效期24小时,请及时下载视频。
{
    "status_code": 200,
    "request_id": "167f3beb-3dd0-47fe-a83c-xxxxxx",
    "code": null,
    "message": "",
    "output": {
        "task_id": "5b65411f-d946-4e29-859e-xxxxxx",
        "task_status": "SUCCEEDED",
        "video_url": "https://dashscope-result-bj.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx",
        "submit_time": "2025-10-23 11:47:23.879",
        "scheduled_time": "2025-10-23 11:47:34.351",
        "end_time": "2025-10-23 11:52:35.323",
        "orig_prompt": "Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective's office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: 'The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them '。",
        "actual_prompt": "Low-angle shot, medium close-up, warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, central composition. In a classic detective's office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its crimson fur contrasting with the dimly lit room. Its tail rests lightly on the edge of the chair, and its fingers slowly turn yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. The fox slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera. Its mouth clearly moves as it speaks in a smooth, cynical voice: \"The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them.\""
    },
    "usage": {
        "video_count": 1,
        "video_duration": 10,
        "video_ratio": "832*480"
    }
}

异步调用

请求示例
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
import os

# 如果使用华北2(北京)地域的模型,需要将url替换为:https://dashscope.aliyuncs.com/api/v1
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'

# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
# 新加坡和北京地域的API Key不同。获取API Key:https://www.alibabacloud.com/help/zh/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY")

def sample_async_call_t2v():
    # call async api, will return the task information
    # you can get task status with the returned task id.
    rsp = VideoSynthesis.async_call(api_key=api_key,
                                    model='wan2.5-t2v-preview',
                                    prompt="Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: 'The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them '.",
                                    audio_url='https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250929/stjqnq/%E7%8B%90%E7%8B%B8.mp3',
                                    size='832*480',
                                    duration=10,
                                    negative_prompt="",
                                    # audio=True,
                                    prompt_extend=True,
                                    watermark=False,
                                    seed=12345)
    print(rsp)
    if rsp.status_code == HTTPStatus.OK:
        print("task_id: %s" % rsp.output.task_id)
    else:
        print('Failed, status_code: %s, code: %s, message: %s' %
              (rsp.status_code, rsp.code, rsp.message))
                           
    # get the task information include the task status.
    status = VideoSynthesis.fetch(task=rsp, api_key=api_key)
    if status.status_code == HTTPStatus.OK:
        print(status.output.task_status)  # check the task status
    else:
        print('Failed, status_code: %s, code: %s, message: %s' %
              (status.status_code, status.code, status.message))

    # wait the task complete, will call fetch interval, and check it's in finished status.
    rsp = VideoSynthesis.wait(task=rsp, api_key=api_key)
    print(rsp)
    if rsp.status_code == HTTPStatus.OK:
        print(rsp.output.video_url)
    else:
        print('Failed, status_code: %s, code: %s, message: %s' %
              (rsp.status_code, rsp.code, rsp.message))


if __name__ == '__main__':
    sample_async_call_t2v()
响应示例

1、创建任务的响应示例

{
	"status_code": 200,
	"request_id": "c86ff7ba-8377-917a-90ed-xxxxxx",
	"code": "",
	"message": "",
	"output": {
		"task_id": "721164c6-8619-4a35-a6d9-xxxxxx",
		"task_status": "PENDING",
		"video_url": ""
	},
	"usage": null
}

2、查询任务结果的响应示例

video_url 有效期24小时,请及时下载视频。
{
    "status_code": 200,
    "request_id": "167f3beb-3dd0-47fe-a83c-xxxxxx",
    "code": null,
    "message": "",
    "output": {
        "task_id": "5b65411f-d946-4e29-859e-xxxxxx",
        "task_status": "SUCCEEDED",
        "video_url": "https://dashscope-result-bj.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx",
        "submit_time": "2025-10-23 11:47:23.879",
        "scheduled_time": "2025-10-23 11:47:34.351",
        "end_time": "2025-10-23 11:52:35.323",
        "orig_prompt": "Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective's office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: 'The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them '。",
        "actual_prompt": "Low-angle shot, medium close-up, warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, central composition. In a classic detective's office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its crimson fur contrasting with the dimly lit room. Its tail rests lightly on the edge of the chair, and its fingers slowly turn yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. The fox slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera. Its mouth clearly moves as it speaks in a smooth, cynical voice: \"The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them.\""
    },
    "usage": {
        "video_count": 1,
        "video_duration": 10,
        "video_ratio": "832*480"
    }
}

Java SDK调用

重要
  • wan2.6-t2v模型暂不支持SDK调用。

  • 请确保 DashScope Java SDK 版本不低于 2.22.2,再运行以下代码。

    若版本过低,可能会触发 “url error, please check url!” 等错误。请参考安装SDK进行更新。

同步调用

请求示例
// Copyright (c) Alibaba, Inc. and its affiliates.

// dashscope sdk >= 2.18.2
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesis;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisParam;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;
import com.alibaba.dashscope.utils.Constants;

import java.util.HashMap;
import java.util.Map;

public class Text2Video {
    /**
     * Create a video compositing task and wait for the task to complete.
     */
    static {
     Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";
     // 如果使用华北2(北京)地域的模型,需要将url替换为:https://dashscope.aliyuncs.com/api/v1
    }
    
    // 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
    // 新加坡和北京地域的API Key不同。获取API Key:https://www.alibabacloud.com/help/zh/model-studio/get-api-key
    public static String apiKey = System.getenv("DASHSCOPE_API_KEY");


    public static void text2Video() throws ApiException, NoApiKeyException, InputRequiredException {
        VideoSynthesis vs = new VideoSynthesis();
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("prompt_extend", true);
        parameters.put("watermark", false);
        parameters.put("seed", 12345);

        VideoSynthesisParam param =
                VideoSynthesisParam.builder()
                        .apiKey(apiKey)
                        .model("wan2.5-t2v-preview")
                        .prompt("Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: 'The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them '.")
                        .audioUrl("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250929/stjqnq/%E7%8B%90%E7%8B%B8.mp3")
                        .negativePrompt("")
                        .size("832*480")
                        .duration(10)
                        // .audio(true)
                        .parameters(parameters)
                        .build();
        System.out.println("please wait...");
        VideoSynthesisResult result = vs.call(param);
        System.out.println(JsonUtils.toJson(result));
    }

    public static void main(String[] args) {
        try {
            text2Video();
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            System.out.println(e.getMessage());
        }
        System.exit(0);
    }
}
响应示例
video_url 有效期24小时,请及时下载视频。
{
    "request_id": "4e9aab26-c50b-4ea7-b2c0-xxxxxx",
    "output": {
        "task_id": "9e0fc846-ee92-42ac-af42-xxxxxx",
        "task_status": "SUCCEEDED",
        "video_url": "https://dashscope-result-sh.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx"
    },
    "usage": {
        "video_count": 1,
        "video_duration": 10,
        "video_ratio": "832*480"
    }
}

异步调用

请求示例
// Copyright (c) Alibaba, Inc. and its affiliates.

import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesis;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisListResult;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisParam;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.task.AsyncTaskListParam;
import com.alibaba.dashscope.utils.JsonUtils;
import com.alibaba.dashscope.utils.Constants;

import java.util.HashMap;
import java.util.Map;

public class Text2Video {
    /**
     * Create a video compositing task and wait for the task to complete.
     */
    static {
        // 如果使用华北2(北京)地域的模型,需要将url替换为:https://dashscope.aliyuncs.com/api/v1
        Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";
    }

     // 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
    // 新加坡和北京地域的API Key不同。获取API Key:https://www.alibabacloud.com/help/zh/model-studio/get-api-key
    public static String apiKey = System.getenv("DASHSCOPE_API_KEY");

    public static void text2Video() throws ApiException, NoApiKeyException, InputRequiredException {
        VideoSynthesis vs = new VideoSynthesis();
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("prompt_extend", true);
        parameters.put("watermark", false);
        parameters.put("seed", 12345);

        VideoSynthesisParam param =
                VideoSynthesisParam.builder()
                        .apiKey(apiKey)
                        .model("wan2.5-t2v-preview")
                        .prompt("Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: 'The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them '.")
                        .audioUrl("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250929/stjqnq/%E7%8B%90%E7%8B%B8.mp3")
                        .negativePrompt("")
                        .size("832*480")
                        .duration(10)
                        // .audio(true)
                        .parameters(parameters)
                        .build();

        // 异步调用
        VideoSynthesisResult task = vs.asyncCall(param);
        System.out.println(JsonUtils.toJson(task));
        System.out.println("please wait...");

        //获取结果
        VideoSynthesisResult result = vs.wait(task, apiKey);
        System.out.println(JsonUtils.toJson(result));
    }

     // 获取任务列表
    public static void listTask() throws ApiException, NoApiKeyException {
        VideoSynthesis is = new VideoSynthesis();
        AsyncTaskListParam param = AsyncTaskListParam.builder().build();
        param.setApiKey(apiKey);
        VideoSynthesisListResult result = is.list(param);
        System.out.println(result);
    }

    // 获取单个任务结果
    public static void fetchTask(String taskId) throws ApiException, NoApiKeyException {
        VideoSynthesis is = new VideoSynthesis();
        // 如果已设置 DASHSCOPE_API_KEY 为环境变量,apiKey 可为空
        VideoSynthesisResult result = is.fetch(taskId, apiKey);
        System.out.println(result.getOutput());
        System.out.println(result.getUsage());
    }

    public static void main(String[] args) {
        try {
            text2Video();
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            System.out.println(e.getMessage());
        }
        System.exit(0);
    }
}
响应示例

1、创建任务的响应示例。

{
        "request_id": "5dbf9dc5-4f4c-9605-85ea-xxxxxxxx",
	"output": {
		"task_id": "7277e20e-aa01-4709-xxxxxxxx",
		"task_status": "PENDING"
	}
}

2、查询任务结果的响应示例

video_url 有效期24小时,请及时下载视频。
{
    "request_id": "4e9aab26-c50b-4ea7-b2c0-xxxxxx",
    "output": {
        "task_id": "9e0fc846-ee92-42ac-af42-xxxxxx",
        "task_status": "SUCCEEDED",
        "video_url": "https://dashscope-result-sh.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx"
    },
    "usage": {
        "video_count": 1,
        "video_duration": 10,
        "video_ratio": "832*480"
    }
}

使用限制

  • 数据时效:任务task_id和 视频url均只保留 24 小时,过期后将无法查询或下载。

  • 音频支持:wan2.5 支持有声视频(自动配音或上传自定义音频)。wan2.2 及早期版本仅输出无声视频,如有需要,可通过语音合成生成音频。

  • 内容审核:输入的 prompt 和输出的视频均会经过内容安全审核,包含违规内容的请求将报错“IPInfringementSuspect”或“DataInspectionFailed”,具体参见错误信息

  • 网络访问配置:视频链接存储于阿里云 OSS,如果业务系统因安全策略无法访问外部OSS链接,请将以下 OSS 域名加入网络访问白名单。

    # OSS域名列表
    dashscope-result-bj.oss-cn-beijing.aliyuncs.com
    dashscope-result-hz.oss-cn-hangzhou.aliyuncs.com
    dashscope-result-sh.oss-cn-shanghai.aliyuncs.com
    dashscope-result-wlcb.oss-cn-wulanchabu.aliyuncs.com
    dashscope-result-zjk.oss-cn-zhangjiakou.aliyuncs.com
    dashscope-result-sz.oss-cn-shenzhen.aliyuncs.com
    dashscope-result-hy.oss-cn-heyuan.aliyuncs.com
    dashscope-result-cd.oss-cn-chengdu.aliyuncs.com
    dashscope-result-gz.oss-cn-guangzhou.aliyuncs.com
    dashscope-result-wlcb-acdr-1.oss-cn-wulanchabu-acdr-1.aliyuncs.com

关键参数说明

设置音频参数

支持的模型:wan2.6-t2v,wan2.5-t2v-preview。

音频设置:通过input.audio_url和 parameters.audio参数组合控制音频行为,参数优先级:audio_url > audio。支持三种模式:

  1. 生成无声视频

    1. 参数设置:不传audio_url,且 audio 为 false。

    2. 适用场景:纯视觉内容展示,后期自行添加音频或配乐。

  2. 自动生成音频

    1. 参数设置:不传audio_url,且 audio 为 true。

    2. 效果说明:模型根据提示词和画面内容,自动生成匹配的背景音频或音乐。

  3. 使用自定义音频

    1. 参数设置:传入 audio_url(此时 audio参数无效)。

    2. 效果说明:视频画面会尝试与音频内容对齐(如口型、节奏等)。

计费与限流

  • 模型免费额度和计费单价请参见模型列表与价格

  • 模型限流请参见通义万相系列

  • 计费说明:

    • 按成功生成的 视频秒数 计费。仅当查询结果接口返回task_statusSUCCEEDED 并成功生成视频后,才会计费。

    • 模型调用失败或处理错误不产生任何费用,也不消耗免费额度

错误码

如果模型调用失败并返回报错信息,请参见错误信息进行解决。

常见问题

Q: 如何查看模型调用量?

A: 模型调用完一小时后,请在模型观测(新加坡)模型观测(北京)页面,查看模型的调用次数、成功率等指标。如何查看模型调用记录?

Q: 如何将临时的视频链接转为永久链接?

A: 不能直接转换该链接。正确的做法是:后端服务获取到url后,通过代码下载该视频文件,然后将其上传到永久对象存储服务(如阿里云 OSS),生成一个新的、永久访问链接。

示例代码:下载视频到本地

import requests

def download_and_save_video(video_url, save_path):
    try:
        response = requests.get(video_url, stream=True, timeout=300) # 设置超时
        response.raise_for_status() # 如果HTTP状态码不是200,则引发异常
        with open(save_path, 'wb') as f:
            for chunk in response.iter_content(chunk_size=8192):
                f.write(chunk)
        print(f"视频已成功下载到: {save_path}")
        # 此处可以接上传到永久存储的逻辑
    except requests.exceptions.RequestException as e:
        print(f"下载视频失败: {e}")

if __name__ == '__main__':
    video_url = "http://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxxx"
    save_path = "video.mp4"
    download_and_save_video(video_url, save_path)

Q: 返回的视频链接可以在浏览器中直接播放吗?

A: 不建议这样做,因为链接会在 24 小时后失效。最佳实践是后端下载转存后,使用永久链接进行视频播放。