跳转到主要内容
Vidu

Vidu — 创建任务

使用 Vidu 模型提交参考视频生成任务。

POST
/services/aigc/video-generation/video-synthesis
curl --location 'https://maas.qianwenaiapi.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/viduq2_reference2video",
  "input": {
    "media": [
      {
        "type": "image",
        "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260320/knsple/wan-r2v-role-frame.jpg"
      },
      {
        "type": "image",
        "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/qpzxps/wan-r2v-object4.png"
      },
      {
        "type": "image",
        "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/wfjikw/wan-r2v-backgroud5.png"
      }
    ],
    "prompt": "男人坐在靠窗的椅子上,手持吉他,在咖啡厅旁演奏一首舒缓的美国乡村民谣"
  },
  "parameters": {
    "duration": 5,
    "size": "1280*720",
    "resolution": "720P",
    "watermark": true
  }
}'
{
  "request_id": "4909100c-7b5a-9f92-bfe5-xxxxxx",
  "output": {
    "task_id": "0385dc79-5ff8-4d82-bcb6-xxxxxx",
    "task_status": "PENDING"
  }
}
生成保留参考图片或视频中主体外观的视频。

可用模型

模型参考输入最大时长
vidu/viduq2_reference2video1–7 张图片10 秒
vidu/viduq2-pro_reference2video1–4 张图片 + 0–2 段视频10 秒

图片要求

  • 格式:JPEG、JPG、PNG 或 WEBP
  • 宽高比:1:4 到 4:1 之间
  • 文件大小:每张图片不超过 50 MB

视频要求(仅 pro 模型)

  • 格式:MP4、AVI 或 MOV
  • 最小尺寸:128 × 128 像素
  • 宽高比:1:4 到 4:1 之间
  • 时长:1–5 秒
  • 文件大小:每段视频不超过 50 MB

轮询结果

该 API 为异步接口。提交任务后:
  1. 记录响应中的 task_id。
  2. 每 15 秒轮询一次查询视频结果。
  3. 当 task_status 为 SUCCEEDED 时,从 output.video_url 获取视频。
  • Python SDK
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
import os

# 若没有配置环境变量,请用千问AI平台API Key将下行替换为:api_key="sk-xxx"
# 获取API Key:https://platform.qianwenai.com/home/api-keys
api_key = os.getenv("DASHSCOPE_API_KEY")

media = [{'type': 'image', 'url': 'https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260713/dtnctw/ad-1.png'}, {'type': 'image', 'url': 'https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260713/bspdpd/ad-2.png'}, {'type': 'image', 'url': 'https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260713/mhsjyy/ad-3.png'}]

def sample_async_call():
    # 异步提交视频生成任务
    rsp = VideoSynthesis.async_call(api_key=api_key,
                                model='vidu/viduq3-ad_reference2video',
                                prompt='一个瑜伽裤的广告。商品是一条左右各有一个口袋的黑色高腰瑜伽裤。亚洲模特开心地说"我现在再也不穿没有口袋的瑜伽裤了"。画面保持清晰、稳定、容易理解。',
                                media=media,
                                size='1080*1920',
                                resolution='1080P',
                                duration=8,
                                watermark=True)
    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))

    # 查询任务状态
    status = VideoSynthesis.fetch(task=rsp, api_key=api_key)
    if status.status_code == HTTPStatus.OK:
        print(status.output.task_status)
    else:
        print('Failed, status_code: %s, code: %s, message: %s' %
              (status.status_code, status.code, status.message))

    # 等待任务完成
    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()

鉴权

string
header
必填

千问AI平台 API Key。详见获取 API Key。

Header 参数

enum<string>
必填

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

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

enable

请求体

application/json
enum<string>
必填

模型名称。

| 模型 | 参考输入 | 最大时长 | |------|---------|--------| | vidu/viduq2_reference2video | 1~7 张图像 | 10 秒 | | vidu/viduq2-pro_reference2video | 1~4 张图像 + 0~2 个视频 | 10 秒 | | vidu/viduq3-ad_reference2video | 广告视频场景 | 15 秒 | | vidu/viduq3-drama_reference2video | 精品剧/AI漫剧场景 | 15 秒 |

如何选择模型:

  • 广告视频:选择 viduq3-ad_reference2video
  • 精品剧/AI漫剧:选择 viduq3-drama_reference2video
  • 通用场景:选择 viduq2-pro_reference2video 或 viduq2_reference2video(viduq3-mix)
  • 追求速度与性价比:选择 viduq2_reference2video(viduq3-turbo)
vidu/viduq3-mix_reference2video,vidu/viduq3_reference2video,vidu/viduq3-turbo_reference2video,vidu/viduq3-ad_reference2video,vidu/viduq3-drama_reference2video,vidu/viduq2_reference2video,vidu/viduq2-pro_reference2video
vidu/viduq3-mix_reference2video
object
必填

输入的基本信息,包括参考图片和提示词。

object

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

响应

200-application/json
string

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

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

任务输出信息。