文生视频API参考

更新时间:2025-04-01 10:21:53

本文介绍通义万相-文生视频模型的输入输出参数。

模型概览

通义万相-文生视频模型,一句话生成视频。视频模型具备强大的指令遵循能力,支持大幅度复杂运动、现实物理规律还原,生成的视频呈现丰富的艺术风格及影视级画面质感。

您可以在通义万相官网体验文生视频的效果。

模型效果示意

输入示例

输出视频

输入示例

输出视频

输入提示词:一只小猫在月光下奔跑

模型简介

模型名称

模型简介

模型名称

模型简介

wanx2.1-t2v-turbo

生成速度更快,表现均衡。

wanx2.1-t2v-plus

生成细节更丰富,画面更具质感。

模型名称

计费单价

限流(主账号与RAM子账号共用)

免费额度

任务下发接口QPS限制

同时处理中任务数量

模型名称

计费单价

限流(主账号与RAM子账号共用)

免费额度

任务下发接口QPS限制

同时处理中任务数量

wanx2.1-t2v-turbo

0.24元/秒

2

2

免费额度:各200

有效期:百炼开通后180天内

wanx2.1-t2v-plus

0.70元/秒

2

2

更多说明请参见模型计费及限流

前提条件

文生视频API支持通过HTTPDashScope SDK进行调用。

在调用前,您需要开通模型服务并获取API Key,再配置API Key到环境变量

如需通过SDK进行调用,请安装DashScope SDK。目前,该SDK已支持PythonJava。

HTTP调用

文生视频模型处理时间较长,为了避免请求超时,HTTP调用仅支持异步获取模型结果。您需要发起两个请求:

  • 创建任务:首先发送一个请求创建任务,该请求会返回任务ID。

  • 根据任务ID查询结果:使用上一步获得的任务ID,查询模型生成的结果。

文生视频耗时较长(约5-10分钟),具体耗时受限于排队任务数量和服务执行情况,请您在获取结果时耐心等待。

创建任务

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

请求参数

文生视频
curl --location 'https://dashscope.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": "wanx2.1-t2v-turbo",
    "input": {
        "prompt": "一只小猫在月光下奔跑"
    },
    "parameters": {
        "size": "1280*720"
    }
}'
请求头(Headers)

Content-Type string (必选)

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

Authorization string(必选)

请求身份认证。接口使用百炼API-Key进行身份认证。示例值:Bearer d1xxx2a。

X-DashScope-Async string (必选)

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

请求体(Request Body)

model string (必选)

模型名称。示例值:wanx2.1-t2v-turbo。

input object (必选)

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

属性

prompt string (必选)

文本提示词。支持中英文,长度不超过800个字符,每个汉字/字母占一个字符,超过部分会自动截断。

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

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

parameters object (可选)

图像处理参数。

属性

size string (可选)

生成视频的分辨率。默认值1280*720。其中,1280代表宽度,720代表高度。

目前支持设置480P720P两个档位的视频分辨率。模型支持的视频分辨率如下:

  • wanx2.1-t2v-turbo: 支持 480P 和 720P 对应的所有分辨率。

  • wanx2.1-t2v-plus: 仅支持 720P 对应的所有分辨率。

480P档位:不同视频宽高比对应的分辨率如下:

  • 16:9:832*480

  • 9:16:480*832

  • 1:1:624*624

720P档位:不同视频宽高比对应的分辨率如下:

  • 16:9:1280*720,默认值。

  • 9:16:720*1280

  • 1:1:960*960

  • 3:4:832*1088

  • 4:3:1088*832

size 参数常见误区:size 参数应直接设置为目标分辨率的具体数值(如 1280*720),而不是宽高比(如 1:1)或分辨率档位名称(如 480P 或 720P)。

duration integer (可选)

生成视频的时长,默认为5,单位为秒。目前仅支持5秒固定时长生成。

prompt_extend bool (可选)

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

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

  • false:不开启智能改写。

seed integer (可选)

随机数种子,用于控制模型生成内容的随机性。取值范围为[0, 2147483647]

如果不提供,则算法自动生成一个随机数作为种子。如果希望生成内容保持相对稳定,可以使用相同的seed参数值。

响应参数

成功响应
异常响应
{
    "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。

task_status string

任务状态。

枚举值

  • PENDING:任务排队中

  • RUNNING:任务处理中

  • SUSPENDED:任务挂起

  • SUCCEEDED:任务执行成功

  • FAILED:任务执行失败

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

request_id string

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

code string

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

message string

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

根据任务ID查询结果

GET https://dashscope.aliyuncs.com/api/v1/tasks/{task_id}

请求参数

查询任务结果

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

curl -X GET \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
https://dashscope.aliyuncs.com/api/v1/tasks/86ecf553-d340-4e21-xxxxxxxxx
请求头(Headers)

Authorization string(必选)

请求身份认证。接口使用百炼API-Key进行身份认证。示例值:Bearer d1xxx2a。

URL路径参数(Path parameters)

task_id string(必选)

任务ID。

响应参数

任务执行成功
任务执行失败

任务数据(如任务状态、视频URL等)仅保留24小时,超时后会被自动清除。请您务必及时保存生成的视频。

{
    "request_id": "851985d0-fbba-9d8d-a17a-xxxxxx",
    "output": {
        "task_id": "208e2fd1-fcb4-4adf-9fcc-xxxxxx",
        "task_status": "SUCCEEDED",
        "submit_time": "2025-01-08 16:43:27.877",
        "scheduled_time": "2025-01-08 16:43:27.908",
        "end_time": "2025-01-08 16:46:35.304",
        "video_url": "https://dashscope-result-wlcb.oss-cn-wulanchabu.aliyuncs.comc/aa.mp4"
    },
    "usage": {
        "video_count": 1
    }
}

如果因为某种原因导致任务执行失败,任务状态将被设置为FAILED,并通过codemessage字段明确指示错误原因。

{
    "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"
    }
}

output object

任务输出信息。

属性

task_id string

任务ID。

task_status string

任务状态。

枚举值

  • PENDING:任务排队中

  • RUNNING:任务处理中

  • SUSPENDED:任务挂起

  • SUCCEEDED:任务执行成功

  • FAILED:任务执行失败

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

submit_time string

任务提交时间。

scheduled_time string

任务执行时间。

end_time string

任务完成时间。

video_url string

视频URL。可通过此URL下载视频。

code string

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

message string

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

usage object

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

属性

video_count integer

生成视频的数量。

request_id string

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

DashScope SDK调用

请先确认已安装最新版DashScope SDK,否则可能运行报错:安装SDK

DashScope SDK目前已支持PythonJava。

SDKHTTP接口的参数名基本一致,参数结构根据不同语言的SDK封装而定。参数说明可参考HTTP调用

由于视频模型处理时间较长,底层服务采用异步方式提供。SDK在上层进行了封装,支持同步、异步两种调用方式。

文生视频耗时较长(约5-10分钟),具体耗时受限于排队任务数和服务执行情况,请您在获取结果时耐心等待。

Python SDK调用

同步调用
异步调用
请求示例
from http import HTTPStatus
# dashscope sdk >= 1.22.1
from dashscope import VideoSynthesis

def sample_sync_call_t2v():
    # call sync api, will return the result
    print('please wait...')
    rsp = VideoSynthesis.call(model='wanx2.1-t2v-turbo',
                              prompt='一只小猫在月光下奔跑',
                              size='1280*720')
    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": "a250655b-c899-9384-b12e-xxxxxx",
	"code": null,
	"message": "",
	"output": {
		"task_id": "04d3cdfb-8405-4e6b-bb03-xxxxxx",
		"task_status": "SUCCEEDED",
		"video_url": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/aaa.mp4",
		"submit_time": "2025-02-12 11:27:12.975",
		"scheduled_time": "2025-02-12 11:29:39.988",
		"end_time": "2025-02-12 11:35:35.801"
	},
	"usage": {
		"video_count": 1,
		"video_duration": 5,
		"video_ratio": "1280*720"
	}
}

请求示例
from http import HTTPStatus
# dashscope sdk >= 1.22.1
from dashscope import VideoSynthesis

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(model='wanx2.1-t2v-turbo',
                                    prompt='一只小猫在月光下奔跑',
                                    size='1280*720')
    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(rsp)
    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(rsp)
    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": "efa545b3-f95c-9e3a-a3b6-xxxxxx",
	"code": null,
	"message": "",
	"output": {
		"task_id": "721164c6-8619-4a35-a6d9-xxxxxx",
		"task_status": "SUCCEEDED",
		"video_url": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/aaaa.mp4",
		"submit_time": "2025-02-12 11:03:30.701",
		"scheduled_time": "2025-02-12 11:06:05.378",
		"end_time": "2025-02-12 11:12:18.853"
	},
	"usage": {
		"video_count": 1,
		"video_duration": 5,
		"video_ratio": "1280*720"
	}
}

Java 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;

public class Text2Video {
    /**
     * Create a video compositing task and wait for the task to complete.
     */
    public static void text2Video() throws ApiException, NoApiKeyException, InputRequiredException {
        VideoSynthesis vs = new VideoSynthesis();
        VideoSynthesisParam param =
                VideoSynthesisParam.builder()
                        .model("wanx2.1-t2v-turbo")
                        .prompt("一只小猫在月光下奔跑")
                        .size("1280*720")
                        .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": "db27ee62-1148-9de4-aab9-xxxxxx",
	"output": {
		"task_id": "31c13f64-60e3-4822-b255-xxxxxx",
		"task_status": "SUCCEEDED",
		"video_url": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/aaa.mp4"
	},
	"usage": {
		"video_count": 1,
		"video_duration": 5,
		"video_ratio": "1280*720"
	}
}
请求示例
// 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;

public class Text2Video {
    /**
     * Create a video compositing task and wait for the task to complete.
     */
    public static void text2Video() throws ApiException, NoApiKeyException, InputRequiredException {
        VideoSynthesis vs = new VideoSynthesis();
        VideoSynthesisParam param =
                VideoSynthesisParam.builder()
                        .model("wanx2.1-t2v-turbo")
                        .prompt("一只小猫在月光下奔跑")
                        .size("1280*720")
                        .build();

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

        //获取结果
        // apiKey 已经配置在环境变量,因此这里可以设置为 null
        VideoSynthesisResult result = vs.wait(task, null);
        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);
    }
}
响应示例

1、创建任务的响应示例

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

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

video_url 有效期24小时,请及时下载视频。
{
	"request_id": "1625235c-c13e-93ec-aff7-xxxxxxxx",
	"output": {
		"task_id": "464a5e46-79a6-46fd-9823-xxxxxxxx",
		"task_status": "SUCCEEDED",
		"video_url": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/aaa.mp4"
	},
	"usage": {
		"video_count": 1,
		"video_duration": 5,
		"video_ratio": "1280*720"
	}
}

错误码

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

API还有特定状态码,具体如下所示。

HTTP状态码

接口错误码(code)

接口错误信息(message)

含义说明

HTTP状态码

接口错误码(code)

接口错误信息(message)

含义说明

400

InvalidParameter

InvalidParameter

请求参数不合法。

400

IPInfringementSuspect

Input data is suspected of being involved in IP infringement.

输入数据(如提示词)可能涉及知识产权侵权风险。请检查输入,确保不包含引发侵权风险的内容。

400

DataInspectionFailed

Input data may contain inappropriate content.

输入数据(如提示词)可能包含敏感内容。请修改输入后重试。

500

InternalError

InternalError

服务异常。请先尝试重试,排除偶发情况。

常见问题

plus 模型是否支持输出 480P 的视频?

不支持。

如需生成 480P 分辨率的视频,请选择 wanx2.1-t2v-turbo 模型,并在参数 size 中指定具体的分辨率数值(如 624*624, 对应 480P 视频)。

文生视频模型支持的输出视频分辨率为:

  • wanx2.1-t2v-turbo: 支持 480P 和 720P 对应的所有分辨率。

  • wanx2.1-t2v-plus: 仅支持 720P 对应的所有分辨率。

模型计费及限流

免费额度

  • 额度说明:免费额度是指模型成功生成的输出视频时长。输入内容异常及模型处理失败的情况不占用免费额度。

  • 领取方式:开通阿里云百炼大模型服务后自动发放,有效期180天。

  • 使用账号:阿里云主账号与其RAM子账号共享免费额度。

  • 更多详情请参见新人免费额度

计费说明

  • 当计费有明确单价时,如0.2元/秒,表示该模型已商业化,免费额度用尽或过期后需付费使用。

  • 计费项:只对模型成功生成的输出视频进行收费,其余情况暂不计费。

  • 付费方式:由阿里云主账号统一付费。RAM子账号不能独立计量计费,必须由所属的主账号付费。如果您需要查询账单信息,请前往阿里云控制台账单概览

  • 充值途径:您可以在阿里云控制台费用与成本页面进行充值。

  • 模型调用情况:您可以前往百炼平台的模型观测查看模型调用量及调用次数。

  • 更多计费问题请参见计费项

限流

  • 限流说明:阿里云主账号与其RAM子账号共享限流限制。

配置域名白名单以访问视频OSS链接

模型生成的视频存储于阿里云OSS,每个视频会被分配一个OSS链接,如https://dashscope-result-xx.oss-cn-xxxx.aliyuncs.com/xxx.mp4。OSS链接允许公开访问,您可以使用此链接下载视频,链接仅在 24 小时内有效 。

特别注意的是,如果您的业务对安全性要求较高,无法访问阿里云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

  • 本页导读 (1)
  • 模型概览
  • 前提条件
  • HTTP调用
  • 创建任务
  • 根据任务ID查询结果
  • DashScope SDK调用
  • Python SDK调用
  • Java SDK调用
  • 错误码
  • 常见问题
  • plus 模型是否支持输出 480P 的视频?
  • 模型计费及限流
  • 配置域名白名单以访问视频OSS链接
AI助理

点击开启售前

在线咨询服务

你好,我是AI助理

可以解答问题、推荐解决方案等