跳转到主要内容
Vidu

Vidu — 创建任务

使用 Vidu 模型提交文生视频任务,异步生成视频。

POST
/services/aigc/video-generation/video-synthesis
cURL
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": "vidu/viduq3-turbo_text2video",
  "input": {
    "prompt": "一只小猫在月光下奔跑"
  },
  "parameters": {
    "size": "960*528",
    "resolution": "540P",
    "duration": 5,
    "watermark": true
  }
}'
{
  "request_id": "4909100c-7b5a-9f92-bfe5-xxxxxx",
  "output": {
    "task_id": "0385dc79-5ff8-4d82-bcb6-xxxxxx",
    "task_status": "PENDING"
  },
  "code": "<string>",
  "message": "<string>"
}
提交文生视频任务后,服务将异步生成视频。提交任务后,使用 查询视频结果 接口轮询任务状态,直到 task_statusSUCCEEDEDFAILED

模型列表

模型最高分辨率最长时长
vidu/viduq3-turbo_text2video1080P16 秒
vidu/viduq3-pro_text2video1080P16 秒
vidu/viduq2_text2video1080P10 秒

HTTP 调用

文生视频接口仅支持异步调用,请求时必须携带请求头 X-DashScope-Async: enable 任务提交成功后返回 task_id,使用 查询视频结果 接口获取生成结果。

size 参数取值对照表

size 参数与 resolution 参数共同控制输出视频的尺寸。两者均传入时以 size 为准。
分辨率档位宽高比size 取值(宽*高)
540P16:9960*528
540P9:16528*960
540P1:1720*720
540P4:3816*608
540P3:4608*816
720P16:91280*720
720P9:16720*1280
720P1:1960*960
720P4:31104*816
720P3:4816*1104
1080P16:91920*1080
1080P9:161080*1920
1080P1:11440*1440
1080P4:31674*1238
1080P3:41238*1674
sizeresolution 均不传时,默认输出 720P 16:9(1280*720)。

DashScope SDK 调用

使用 SDK 调用时,需安装对应版本的 DashScope SDK:
  • Python SDK:版本 >= 1.25.8
  • Java SDK:版本 >= 2.22.6
安装方法参见安装 DashScope SDK

Python SDK

from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
import os

dashscope.base_http_api_url = 'https://dashscope.aliyuncs.com/api/v1'

# 若没有配置环境变量,请用 API Key 将下行替换为:api_key="sk-xxx"
api_key = os.getenv("DASHSCOPE_API_KEY")

def sample_sync_call_t2v():
  print('please wait...')
  rsp = VideoSynthesis.call(api_key=api_key,
                            model='vidu/viduq3-turbo_text2video',
                            prompt='一只小猫在月光下奔跑',
                            size='960*528',
                            duration=5,
                            resolution='540P',
                            watermark=True)
  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()

Java SDK

// Copyright (c) Alibaba, Inc. and its affiliates.
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;

public class Text2Video {
    static {
        Constants.baseHttpApiUrl = "https://dashscope.aliyuncs.com/api/v1";
    }
    public static String apiKey = System.getenv("DASHSCOPE_API_KEY");

    public static void text2Video() throws ApiException, NoApiKeyException, InputRequiredException {
        VideoSynthesis vs = new VideoSynthesis();
        VideoSynthesisParam param =
                VideoSynthesisParam.builder()
                        .apiKey(apiKey)
                        .model("vidu/viduq3-turbo_text2video")
                        .prompt("一只小猫在月光下奔跑")
                        .size("960*528")
                        .resolution("540P")
                        .duration(5)
                        .watermark(true)
                        .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);
    }
}

鉴权

string
header
必填

千问云 API Key。详见获取 API Key

Header 参数

enum<string>
必填

请求内容类型,必须设置为 application/json。

application/json
enum<string>
必填

异步处理配置参数。HTTP 请求只支持异步,必须设置为 enable。缺少此请求头将报错:"current user api does not support synchronous calls"。

enable

请求体

application/json
enum<string>
必填

模型名称。

vidu/viduq3-turbo_text2video,vidu/viduq3-pro_text2video,vidu/viduq2_text2video
vidu/viduq3-turbo_text2video
object
必填

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

object

视频生成参数,如设置视频分辨率、时长等。

响应

200-application/json
string

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

4909100c-7b5a-9f92-bfe5-xxxxxx
object

任务输出信息。

string

请求失败的错误码。请求成功时不会返回此参数。

string

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