万相3.0调用说明

本文介绍万相 3.0 视频生成调用方式,具体细节可参考 万相3.0 官方 API 文档。

本平台调用示例

以下以 wan3.0-video(标准版)为例,高速版使用 wan3.0-video-prime。

创建任务

下面以图片、视频和音频参考生视频为例。实际使用时,按需保留 input.media 中的素材,并将示例地址替换为可访问的真实地址;文生视频直接删除 media,图生视频则改用 first_frame 或 first_frame + last_frame。

首帧 / 首尾帧不能与参考素材混用;文件或网页参考使用 file 或 link(二选一)。

curl -X POST 'https://api.token-hubs.com/api/v1/services/aigc/video-generation/video-synthesis' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'X-DashScope-Async: enable' \
  -d '{
    "model": "wan3.0-video",
    "input": {
      "prompt": "以图1中的人物为主角,参考视频1的镜头运动,在海边漫步,配合音频1的节奏生成短片。",
      "media": [
        { "type": "reference_image", "url": "https://example.com/person.jpg" },
        { "type": "reference_video", "url": "https://example.com/motion.mp4" },
        { "type": "reference_audio", "url": "https://example.com/music.mp3" }
      ]
    },
    "parameters": {
      "resolution": "720P",
      "ratio": "adaptive",
      "duration": 5,
      "audio": true,
      "prompt_extend": true,
      "watermark": false,
      "seed": 42
    }
  }'

返回体(创建成功后返回 output.task_id,用于后续查询任务状态):

{
  "output": {
    "task_status": "PENDING",
    "task_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
  },
  "request_id": "request-xxxxxxxx"
}

查询任务

使用 GET https://api.token-hubs.com/api/v1/tasks/{task_id} 查询任务,请求头携带 Authorization: Bearer YOUR_API_KEY,将 {task_id} 替换为创建任务时返回的 output.task_id。

output.task_status 为 PENDING / RUNNING 时继续轮询;为 SUCCEEDED 时,output.video_url 即为视频下载地址。成功返回体的主要字段如下:

{
  "output": {
    "task_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "task_status": "SUCCEEDED",
    "video_url": "https://example.com/generated-video.mp4"
  },
  "usage": {
    "video_count": 1,
    "duration": 5.0,
    "input_video_duration": 10.0,
    "output_video_duration": 5.0,
    "fps": 30,
    "SR": 720,
    "ratio": "16:9"
  },
  "request_id": "request-xxxxxxxx"
}

视频生成为异步任务,建议每隔约 15 秒查询一次。遇到 FAILED 时读取 output.code 和 output.message 排查原因;CANCELED / UNKNOWN 时停止轮询。任务 ID 和视频链接有效期均为 24 小时,请及时查询并下载转存。

注意事项

请求参数说明

  • 请求结构与官方一致:model、input、parameters 放在请求体顶层;提示词和素材放入 input,生成参数放入 parameters。
  • media 字段:每项通过 type 和 url 指定素材。提示词中的「图1」「视频1」「音频1」按各自类型在数组中的顺序分别编号;视频编辑或延长使用 reference_video,并在提示词中描述相应要求。
  • 分辨率与比例:resolution 可选 480P、720P、1080P;ratio 可选 adaptive、21:9、16:9、4:3、1:1、3:4、9:16。
  • 时长:duration 为 2–30 的整数秒,或 -1(智能时长);有视频输入时,输入与输出视频总时长不得超过 30 秒。
  • 其他参数:audio 控制是否生成声音,prompt_extend 控制提示词改写,watermark 控制水印,seed 为随机种子。使用 file 或 link 时,prompt_extend 必须为 true。
  • 接口地址与鉴权:沿用官方路径,仅将域名替换为 https://api.token-hubs.com,使用本平台 API Key;创建任务时保留 X-DashScope-Async: enable 请求头。