跳转到主要内容
POST
/
wan
/
api
/
v1
/
services
/
aigc
/
video-generation
/
video-synthesis
参考图生视频:参考图/视频保持主体特征创建视频任务
curl --request POST \
  --url https://api.apiyi.com/wan/api/v1/services/aigc/video-generation/video-synthesis \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --header 'X-DashScope-Async: <x-dashscope-async>' \
  --data '
{
  "model": "wan2.7-r2v",
  "input": {
    "prompt": "一位身穿这件礼服的女孩在洒满夕阳的花园里缓步行走,微风轻拂裙摆,电影级光影",
    "media": [
      {
        "type": "reference_image",
        "url": "https://your-cdn.com/dress.png"
      }
    ]
  }
}
'
import requests

url = "https://api.apiyi.com/wan/api/v1/services/aigc/video-generation/video-synthesis"

payload = {
    "model": "wan2.7-r2v",
    "input": {
        "prompt": "一位身穿这件礼服的女孩在洒满夕阳的花园里缓步行走,微风轻拂裙摆,电影级光影",
        "media": [
            {
                "type": "reference_image",
                "url": "https://your-cdn.com/dress.png"
            }
        ]
    }
}
headers = {
    "X-DashScope-Async": "<x-dashscope-async>",
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
  method: 'POST',
  headers: {
    'X-DashScope-Async': '<x-dashscope-async>',
    Authorization: 'Bearer <token>',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    model: 'wan2.7-r2v',
    input: {
      prompt: '一位身穿这件礼服的女孩在洒满夕阳的花园里缓步行走,微风轻拂裙摆,电影级光影',
      media: [{type: 'reference_image', url: 'https://your-cdn.com/dress.png'}]
    }
  })
};

fetch('https://api.apiyi.com/wan/api/v1/services/aigc/video-generation/video-synthesis', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.apiyi.com/wan/api/v1/services/aigc/video-generation/video-synthesis",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode([
    'model' => 'wan2.7-r2v',
    'input' => [
        'prompt' => '一位身穿这件礼服的女孩在洒满夕阳的花园里缓步行走,微风轻拂裙摆,电影级光影',
        'media' => [
                [
                                'type' => 'reference_image',
                                'url' => 'https://your-cdn.com/dress.png'
                ]
        ]
    ]
  ]),
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer <token>",
    "Content-Type: application/json",
    "X-DashScope-Async: <x-dashscope-async>"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.apiyi.com/wan/api/v1/services/aigc/video-generation/video-synthesis"

	payload := strings.NewReader("{\n  \"model\": \"wan2.7-r2v\",\n  \"input\": {\n    \"prompt\": \"一位身穿这件礼服的女孩在洒满夕阳的花园里缓步行走,微风轻拂裙摆,电影级光影\",\n    \"media\": [\n      {\n        \"type\": \"reference_image\",\n        \"url\": \"https://your-cdn.com/dress.png\"\n      }\n    ]\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("X-DashScope-Async", "<x-dashscope-async>")
	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://api.apiyi.com/wan/api/v1/services/aigc/video-generation/video-synthesis")
  .header("X-DashScope-Async", "<x-dashscope-async>")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"model\": \"wan2.7-r2v\",\n  \"input\": {\n    \"prompt\": \"一位身穿这件礼服的女孩在洒满夕阳的花园里缓步行走,微风轻拂裙摆,电影级光影\",\n    \"media\": [\n      {\n        \"type\": \"reference_image\",\n        \"url\": \"https://your-cdn.com/dress.png\"\n      }\n    ]\n  }\n}")
  .asString();
require 'uri'
require 'net/http'

url = URI("https://api.apiyi.com/wan/api/v1/services/aigc/video-generation/video-synthesis")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["X-DashScope-Async"] = '<x-dashscope-async>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"model\": \"wan2.7-r2v\",\n  \"input\": {\n    \"prompt\": \"一位身穿这件礼服的女孩在洒满夕阳的花园里缓步行走,微风轻拂裙摆,电影级光影\",\n    \"media\": [\n      {\n        \"type\": \"reference_image\",\n        \"url\": \"https://your-cdn.com/dress.png\"\n      }\n    ]\n  }\n}"

response = http.request(request)
puts response.read_body
{
  "output": {
    "task_id": "acda59b4-3b10-4789-a5e5-edadae48adcb",
    "task_status": "PENDING"
  },
  "request_id": "..."
}
右侧 Playground 可直接调试:在 AuthorizationBearer sk-your-api-key,填好 model / input.media / parameters 后发起请求。提交成功返回 task_id,轮询与下载见下方说明。
本页是 wan2.7-r2v(参考图生视频)的创建接口:给参考图/参考视频,模型保留其中的主体(人物/动物/物体)和场景特征,生成单角色表演或多角色互动视频。需要更多参考图(≤9 张)可考虑 HappyHorse r2v。完整异步流程见 Wan 概览
  • 参考素材引用约定:prompt 中用「图1 / 图2」指代 reference_image、「视频1 / 视频2」指代 reference_video,顺序与 media 数组一致(图和视频分别计数)。仅一张图/一个视频时可简写为「参考图片」「参考视频」。
  • 数量限制reference_image + reference_video 合计 ≤5;first_frame 最多 1 张。
  • 创建请求走 /wan/api/v1/... 并带 X-DashScope-Async: enable,不要用 /v1/videos

代码示例

curl -X POST "https://api.apiyi.com/wan/api/v1/services/aigc/video-generation/video-synthesis" \
  -H "X-DashScope-Async: enable" \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "wan2.7-r2v",
    "input": {
      "prompt": "一位身穿这件礼服的女孩在洒满夕阳的花园里缓步行走,微风轻拂裙摆,电影级光影",
      "media": [
        {"type": "reference_image", "url": "https://your-cdn.com/dress.png"}
      ]
    },
    "parameters": {"resolution": "720P", "duration": 5, "prompt_extend": true, "watermark": true}
  }'
import requests

url = "https://api.apiyi.com/wan/api/v1/services/aigc/video-generation/video-synthesis"
headers = {
    "Authorization": "Bearer sk-your-api-key",
    "Content-Type": "application/json",
    "X-DashScope-Async": "enable",
}
body = {
    "model": "wan2.7-r2v",
    "input": {
        "prompt": "参考图片,一位女孩在洒满夕阳的花园里缓步行走,电影级光影",
        "media": [{"type": "reference_image", "url": "https://your-cdn.com/girl.png"}],
    },
    "parameters": {"resolution": "720P", "duration": 5, "prompt_extend": True},
}
resp = requests.post(url, json=body, headers=headers, timeout=30)
print("task_id:", resp.json()["output"]["task_id"])
import requests

# 多主体:图1 = 女孩(带音色),视频1 = 男孩(带音色),图2/图3 = 道具/背景
body = {
    "model": "wan2.7-r2v",
    "input": {
        "prompt": "视频1抱着图2,路过图1,并说道:今天的阳光真好。",
        "media": [
            {"type": "reference_image", "url": "https://your-cdn.com/girl.jpg",
             "reference_voice": "https://your-cdn.com/girl-voice.mp3"},
            {"type": "reference_video", "url": "https://your-cdn.com/boy.mp4",
             "reference_voice": "https://your-cdn.com/boy-voice.mp3"},
            {"type": "reference_image", "url": "https://your-cdn.com/object.png"},
        ],
    },
    "parameters": {"resolution": "720P", "ratio": "16:9", "duration": 10, "prompt_extend": False, "watermark": True},
}
resp = requests.post(
    "https://api.apiyi.com/wan/api/v1/services/aigc/video-generation/video-synthesis",
    json=body,
    headers={"Authorization": "Bearer sk-your-api-key", "Content-Type": "application/json",
             "X-DashScope-Async": "enable"},
    timeout=30,
)
print(resp.json()["output"]["task_id"])

参数与媒体速查

参数类型必填默认说明
modelstring固定 wan2.7-r2v
input.promptstring≤5000 字符,用「图1/视频1」指代参考素材
input.mediaarray见下方媒体表
parameters.resolutionstring1080P720P / 1080P
parameters.ratiostring16:916:9 / 9:16 / 1:1 / 4:3 / 3:4(传首帧图时忽略)
parameters.durationint5含参考视频时 2–10;不含时 2–15
parameters.prompt_extendbooltrue智能改写
parameters.watermarkboolfalse「AI 生成」水印

media[] 取值

type张数/限制说明
reference_image与 video 合计 ≤5参考图,提供主体(人物/动物/物体)或场景;可附 reference_voice 指定音色
reference_video与 image 合计 ≤5参考视频,提供主体与音色参考;不建议传空镜视频
first_frame≤1可选首帧,联合控制起始画面
reference_voice附属字段附在某条 reference_image/reference_video 上,指定该主体音色(wav/mp3,1–10s)

响应格式

{
  "output": { "task_id": "acda59b4-3b10-4789-a5e5-edadae48adcb", "task_status": "PENDING" },
  "request_id": "..."
}

查询状态与下载视频

拿到 task_id 后,按以下三步查询状态并下载 mp4:
  • 轮询 GET /v1/tasks/{task_id}(带 Authorization,查询不需要 X-DashScope-Async 头),每 10 秒一次(不要 < 3 秒),直到 status 变为 completed。参考生视频耗时通常 1–5 分钟,建议客户端超时设 20 分钟兜底。
  • 状态取值submitted(排队)/ in_progress(生成中,progress 常停在 30% 属正常)/ completed(成功)/ failed(失败,看 error)。
  • 下载:从响应的 result_url 直接 GET,不要带 Authorization(OSS 签名直链,带了反而 403);result_url 默认 24 小时过期,务必尽快转存。
curl "https://api.apiyi.com/v1/tasks/acda59b4-3b10-4789-a5e5-edadae48adcb" \
  -H "Authorization: Bearer sk-your-api-key"
{
  "status": "completed",
  "progress": 100,
  "result_url": "https://dashscope-result-xxx.oss-cn-beijing.aliyuncs.com/xxx.mp4?Expires=...&Signature=...",
  "task_id": "acda59b4-3b10-4789-a5e5-edadae48adcb"
}
# result_url 是 OSS 签名直链,下载时不要带 Authorization 头(带了反而 403)
curl -L -o out.mp4 "https://dashscope-result-xxx.oss-cn-beijing.aliyuncs.com/xxx.mp4?Expires=...&Signature=..."
TASK_ID="acda59b4-3b10-4789-a5e5-edadae48adcb"
URL=$(curl -s "https://api.apiyi.com/v1/tasks/$TASK_ID" \
  -H "Authorization: Bearer sk-your-api-key" | jq -r '.result_url')
curl -L -o out.mp4 "$URL"   # 不带 Authorization
上面是「已有 task_id」的快捷查询/下载。完整轮询循环(含超时兜底)与 Python 客户端见 Wan 概览 · 异步调用流程

授权

Authorization
string
header
必填

在 API易控制台获取的 API Key

请求头

X-DashScope-Async
enum<string>
默认值:enable
必填

异步处理开关,必须设置为 enable

可用选项:
enable

请求体

application/json
model
enum<string>
默认值:wan2.7-r2v
必填

模型 ID,参考图生视频可填 wan2.7-r2v(历史版本 wan2.6-r2v / wan2.6-r2v-flash)

可用选项:
wan2.7-r2v,
wan2.6-r2v,
wan2.6-r2v-flash
input
object
必填
parameters
object

响应

任务已提交,返回 task_id 与 PENDING 状态

output
object
request_id
string

请求唯一标识

示例:

"..."