跳转到主要内容
万相 2.6 及更早版本

Wan — 创建任务

提交文生视频任务(wan2.6 及更早版本)

POST
/services/aigc/video-generation/video-synthesis
import os
import dashscope
from dashscope.v2 import DashScopeError

client = dashscope.Client(
  api_key=os.getenv("DASHSCOPE_API_KEY"),
  base_url="https://maas.qianwenaiapi.com/api/v1",
)

print('please wait...')
try:
  # generate 为一步式调用(提交任务并等待完成),返回已完成的 Job
  # shot_type 不在具名签名内,经 parameters 透传
  job = client.videos.generate(
    model='wan2.6-t2v',
    prompt='A thrilling detective chase story with cinematic storytelling. Shot 1 [0–3 s]: Wide shot of a rainy New York street at night, neon lights flickering, a detective in a black trench coat walking briskly. Shot 2 [3–6 s]: Medium shot of the detective entering an old building, rain soaking his coat, the door closing slowly behind him. Shot 3 [6–9 s]: Close-up of the detective\'s focused, determined eyes as distant sirens wail and he frowns slightly in thought. Shot 4 [9–12 s]: Medium shot of the detective moving carefully down a dim hallway, his flashlight illuminating the path ahead. Shot 5 [12–15 s]: Close-up of the detective discovering a key clue, his face lighting up with sudden realization.',
    size="1280*720",
    duration=15,
    prompt_extend=True,
    watermark=False,
    parameters={'shot_type': "multi"})
  print(job)
  print("video_url:", job.video_url)
except DashScopeError as e:
  print(f"HTTP返回码:{e.status_code}")
  print(f"错误码:{e.code}")
  print(f"错误信息:{e.message}")
  print("请参考文档:/api-reference/preparation/error-messages")
{
  "request_id": "c1209113-8437-424f-a386-xxxxxx",
  "output": {
    "task_id": "966cebcd-dedc-4962-af88-xxxxxx",
    "task_status": "PENDING"
  }
}
Wan 文生视频模型支持文本、图片和音频输入,可生成最长 15 秒、最高 1080P 分辨率的视频。
  • 核心能力:支持整数时长(2–15 秒)、自定义分辨率(480P、720P、1080P)、提示词改写和水印。
  • 音频能力:支持自动配音或自定义音频文件,实现音视频同步。(wan2.5 和 wan2.6 支持)
  • 多镜头叙事:支持多镜头生成,转场时主体保持一致。(仅 wan2.6 支持)

鉴权

string
header
必填

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

Header 参数

enum<string>
必填

异步任务提交时必须设置为 enable。

enable

请求体

application/json
enum<string>
必填

模型名称。支持的模型及其能力详见端点描述中的模型列表。

wan2.6-t2v,wan2.5-t2v-preview,wan2.2-t2v-plus,wanx2.1-t2v-turbo,wanx2.1-t2v-plus
wan2.6-t2v
object
必填

视频生成的输入数据。

object

视频生成参数。

响应

200-application/json
string

请求的唯一标识符,用于追踪和排查问题。

c1209113-8437-424f-a386-xxxxxx
object