MAGI-2 视频生成 API

使用模型 magi-2 生成 4–30 秒的 1080p 视频,可选择同步生成音频。在体验中心可用文字生成视频,首尾帧和图像、视频、音频参考请通过 API 提交。

一览

model
magi-2
resolution
固定 1080p,省略时也使用 1080p
duration / seconds
4–30 整秒,默认 5。数字和整数字符串均可。两个字段同时传入时取值须一致。
aspect_ratio
文生和参考模式支持 16:9 / 9:16 / 1:1 / 4:3 / 3:4 / 21:9,默认 16:9。首尾帧可省略比例,让输出跟随首帧。
generate_audio
布尔值,默认 true。设为 false 可关闭音频。若同时传入别名 audio,两者须一致。
计费
提交时按所选输出时长全额预扣。以 1× 分组 ¥0.728/秒为例,默认 5 秒 ¥3.64。成功保留扣费,任务失败退回预扣额度。实时价格以模型广场为准。

接入步骤

  1. 1

    提交文生视频

    设置环境变量 WANAPIS_API_KEY。使用 POST /v1/video/generations 发送请求,model 和非空 prompt 必填。提交成功后保存 data.task_id。

    cURL
    curl -fsS "https://api.wanapis.com/v1/video/generations" \
      -H "Authorization: Bearer $WANAPIS_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
      "model": "magi-2",
      "prompt": "A slow tracking shot of a paper boat drifting through a rain puddle",
      "resolution": "1080p",
      "duration": 5,
      "aspect_ratio": "16:9",
      "generate_audio": true
    }'
  2. 2

    用首帧或首尾帧生成

    传入可公开下载的图片 URL。image_urls 的第一项是首帧,第二项可选,为尾帧。也可用 first_frame_image 和 last_frame_image 分别指定。首尾帧模式请单独提交。

    首尾帧请求体(替换为你的文件 URL)
    {
      "model": "magi-2",
      "prompt": "The paper boat drifts from the opening frame to the closing frame",
      "duration": 5,
      "image_urls": [
        "https://example.com/opening.jpg",
        "https://example.com/closing.jpg"
      ],
      "generate_audio": false
    }
  3. 3

    添加多模态参考

    设置 omni_reference_task_type 为 reference 可指定参考模式。image_urls 与 image_with_roles 中的 reference_image 合计最多 10 张,video_urls 和 audio_urls 各最多 5 段。先将素材放到可公开下载的 HTTPS 地址,再填入对应数组。

    图像、视频与音频参考请求体(替换为你的文件 URL)
    {
      "model": "magi-2",
      "prompt": "Keep the boat from the image and follow the camera motion and rhythm of the reference clips",
      "duration": 8,
      "aspect_ratio": "16:9",
      "omni_reference_task_type": "reference",
      "image_urls": [
        "https://example.com/boat.jpg"
      ],
      "video_urls": [
        "https://example.com/camera.mp4"
      ],
      "audio_urls": [
        "https://example.com/rain.mp3"
      ]
    }
  4. 4

    轮询原任务

    将 TASK_ID 替换为提交返回的 data.task_id。每 5 秒左右查询一次。data.status 为 SUCCESS 时读取 data.result_url,为 FAILURE 时查看 data.fail_reason。等待期间继续查询同一个任务 ID。

    查询任务
    TASK_ID=task_example
    curl -fsS "https://api.wanapis.com/v1/video/generations/$TASK_ID" \
      -H "Authorization: Bearer $WANAPIS_API_KEY"
  5. 5

    下载 MP4

    任务成功后请求 data.result_url,继续用提交时的 Bearer API Key。也可按下例通过任务 ID 下载。媒体地址有有效期,建议及时保存到本地。

    保存视频
    curl -fsS "https://api.wanapis.com/v1/videos/$TASK_ID/content" \
      -H "Authorization: Bearer $WANAPIS_API_KEY" \
      -o magi-2.mp4

常见问题

可以请求 720p、自动时长或小数秒吗?

支持的规格为固定 1080p 与 4–30 整秒。省略时长时使用 5 秒。

浏览器直接打开下载链接为什么返回 401?

网关下载地址需要任务所有者的 Bearer API Key 或对应控制台登录会话。脚本可以在 Authorization 请求头传入 Key。

现在就把 MAGI-2 接到 WanAPIs

一个 API Key 调用 GPT、Claude、Gemini、DeepSeek、Kimi、GLM 等模型,国内直连、按 token 实付。