图生视频:首帧图(+ 可选驱动音频)创建视频生成任务
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-i2v",
"input": {
"prompt": "一个由喷漆所画成的少年从墙上活过来,演唱英文 rap,夜晚铁路桥下,电影级光影",
"media": [
{
"type": "first_frame",
"url": "https://your-cdn.com/rap.png"
},
{
"type": "driving_audio",
"url": "https://your-cdn.com/rap.mp3"
}
]
}
}
'import requests
url = "https://api.apiyi.com/wan/api/v1/services/aigc/video-generation/video-synthesis"
payload = {
"model": "wan2.7-i2v",
"input": {
"prompt": "一个由喷漆所画成的少年从墙上活过来,演唱英文 rap,夜晚铁路桥下,电影级光影",
"media": [
{
"type": "first_frame",
"url": "https://your-cdn.com/rap.png"
},
{
"type": "driving_audio",
"url": "https://your-cdn.com/rap.mp3"
}
]
}
}
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-i2v',
input: {
prompt: '一个由喷漆所画成的少年从墙上活过来,演唱英文 rap,夜晚铁路桥下,电影级光影',
media: [
{type: 'first_frame', url: 'https://your-cdn.com/rap.png'},
{type: 'driving_audio', url: 'https://your-cdn.com/rap.mp3'}
]
}
})
};
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-i2v',
'input' => [
'prompt' => '一个由喷漆所画成的少年从墙上活过来,演唱英文 rap,夜晚铁路桥下,电影级光影',
'media' => [
[
'type' => 'first_frame',
'url' => 'https://your-cdn.com/rap.png'
],
[
'type' => 'driving_audio',
'url' => 'https://your-cdn.com/rap.mp3'
]
]
]
]),
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-i2v\",\n \"input\": {\n \"prompt\": \"一个由喷漆所画成的少年从墙上活过来,演唱英文 rap,夜晚铁路桥下,电影级光影\",\n \"media\": [\n {\n \"type\": \"first_frame\",\n \"url\": \"https://your-cdn.com/rap.png\"\n },\n {\n \"type\": \"driving_audio\",\n \"url\": \"https://your-cdn.com/rap.mp3\"\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-i2v\",\n \"input\": {\n \"prompt\": \"一个由喷漆所画成的少年从墙上活过来,演唱英文 rap,夜晚铁路桥下,电影级光影\",\n \"media\": [\n {\n \"type\": \"first_frame\",\n \"url\": \"https://your-cdn.com/rap.png\"\n },\n {\n \"type\": \"driving_audio\",\n \"url\": \"https://your-cdn.com/rap.mp3\"\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-i2v\",\n \"input\": {\n \"prompt\": \"一个由喷漆所画成的少年从墙上活过来,演唱英文 rap,夜晚铁路桥下,电影级光影\",\n \"media\": [\n {\n \"type\": \"first_frame\",\n \"url\": \"https://your-cdn.com/rap.png\"\n },\n {\n \"type\": \"driving_audio\",\n \"url\": \"https://your-cdn.com/rap.mp3\"\n }\n ]\n }\n}"
response = http.request(request)
puts response.read_body{
"output": {
"task_id": "f8ca39a0-6f4b-4ec2-99bf-8b9649d946c4",
"task_status": "PENDING"
},
"request_id": "..."
}Wan2.7 视频生成(阿里云)
Wan2.7 图生视频 API 参考
Wan2.7-i2v 图生视频 API 参考与在线调试:首帧图生成视频,支持 driving_audio 驱动音频做对口型 / rap。
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-i2v",
"input": {
"prompt": "一个由喷漆所画成的少年从墙上活过来,演唱英文 rap,夜晚铁路桥下,电影级光影",
"media": [
{
"type": "first_frame",
"url": "https://your-cdn.com/rap.png"
},
{
"type": "driving_audio",
"url": "https://your-cdn.com/rap.mp3"
}
]
}
}
'import requests
url = "https://api.apiyi.com/wan/api/v1/services/aigc/video-generation/video-synthesis"
payload = {
"model": "wan2.7-i2v",
"input": {
"prompt": "一个由喷漆所画成的少年从墙上活过来,演唱英文 rap,夜晚铁路桥下,电影级光影",
"media": [
{
"type": "first_frame",
"url": "https://your-cdn.com/rap.png"
},
{
"type": "driving_audio",
"url": "https://your-cdn.com/rap.mp3"
}
]
}
}
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-i2v',
input: {
prompt: '一个由喷漆所画成的少年从墙上活过来,演唱英文 rap,夜晚铁路桥下,电影级光影',
media: [
{type: 'first_frame', url: 'https://your-cdn.com/rap.png'},
{type: 'driving_audio', url: 'https://your-cdn.com/rap.mp3'}
]
}
})
};
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-i2v',
'input' => [
'prompt' => '一个由喷漆所画成的少年从墙上活过来,演唱英文 rap,夜晚铁路桥下,电影级光影',
'media' => [
[
'type' => 'first_frame',
'url' => 'https://your-cdn.com/rap.png'
],
[
'type' => 'driving_audio',
'url' => 'https://your-cdn.com/rap.mp3'
]
]
]
]),
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-i2v\",\n \"input\": {\n \"prompt\": \"一个由喷漆所画成的少年从墙上活过来,演唱英文 rap,夜晚铁路桥下,电影级光影\",\n \"media\": [\n {\n \"type\": \"first_frame\",\n \"url\": \"https://your-cdn.com/rap.png\"\n },\n {\n \"type\": \"driving_audio\",\n \"url\": \"https://your-cdn.com/rap.mp3\"\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-i2v\",\n \"input\": {\n \"prompt\": \"一个由喷漆所画成的少年从墙上活过来,演唱英文 rap,夜晚铁路桥下,电影级光影\",\n \"media\": [\n {\n \"type\": \"first_frame\",\n \"url\": \"https://your-cdn.com/rap.png\"\n },\n {\n \"type\": \"driving_audio\",\n \"url\": \"https://your-cdn.com/rap.mp3\"\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-i2v\",\n \"input\": {\n \"prompt\": \"一个由喷漆所画成的少年从墙上活过来,演唱英文 rap,夜晚铁路桥下,电影级光影\",\n \"media\": [\n {\n \"type\": \"first_frame\",\n \"url\": \"https://your-cdn.com/rap.png\"\n },\n {\n \"type\": \"driving_audio\",\n \"url\": \"https://your-cdn.com/rap.mp3\"\n }\n ]\n }\n}"
response = http.request(request)
puts response.read_body{
"output": {
"task_id": "f8ca39a0-6f4b-4ec2-99bf-8b9649d946c4",
"task_status": "PENDING"
},
"request_id": "..."
}右侧 Playground 可直接调试:在 Authorization 填
Bearer sk-your-api-key,填好 model / input.media / parameters 后发起请求。提交成功返回 task_id,轮询与下载见下方说明。本页是
wan2.7-i2v(图生视频)的创建接口:给一张首帧图 + prompt,让画面动起来;可选传 driving_audio 让人像跟随音频做口型/节奏。完整异步流程见 Wan 概览。- 音频驱动是
wan2.7-i2v专属能力:HappyHorse 的 i2v 不支持driving_audio,做对口型 / rap 必须用wan2.7-i2v。 input.media必填,否则上游报图生视频模型 ... 必须提供图片。媒体url必须是公网可直接 GET 的 https 链接。- 创建请求走
/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-i2v",
"input": {
"prompt": "一个由喷漆所画成的少年从墙上活过来,演唱英文 rap,夜晚铁路桥下,电影级光影",
"media": [
{"type": "first_frame", "url": "https://your-cdn.com/rap.png"},
{"type": "driving_audio", "url": "https://your-cdn.com/rap.mp3"}
]
},
"parameters": {"resolution": "720P", "duration": 10, "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-i2v",
"input": {
"prompt": "一个由喷漆所画成的少年从墙上活过来,演唱英文 rap,夜晚铁路桥下",
"media": [
{"type": "first_frame", "url": "https://your-cdn.com/rap.png"},
{"type": "driving_audio", "url": "https://your-cdn.com/rap.mp3"}, # 可选,做对口型
],
},
"parameters": {"resolution": "720P", "duration": 10, "prompt_extend": True, "watermark": True},
}
resp = requests.post(url, json=body, headers=headers, timeout=30)
print("task_id:", resp.json()["output"]["task_id"])
import requests
# 仅首帧图,不做对口型时只传 first_frame
body = {
"model": "wan2.7-i2v",
"input": {
"prompt": "一只猫在草地上奔跑,阳光明媚,镜头跟随",
"media": [{"type": "first_frame", "url": "https://your-cdn.com/cat.png"}],
},
"parameters": {"resolution": "720P", "duration": 5, "prompt_extend": 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"])
参数与媒体速查
| 参数 | 类型 | 必填 | 默认 | 说明 |
|---|---|---|---|---|
model | string | ✓ | — | 固定 wan2.7-i2v |
input.prompt | string | ✓ | — | 文本提示词 |
input.media | array | ✓ | — | 见下方媒体表 |
parameters.resolution | string | 720P | 720P / 1080P | |
parameters.duration | int | 5 | 2–15 秒整数 | |
parameters.prompt_extend | bool | true | 智能改写,推荐开启 | |
parameters.watermark | bool | false | 「AI 生成」水印 |
media[] 取值
type | 必填 | 张数 | 说明 |
|---|---|---|---|
first_frame | ✓ | 1 | 首帧图,视频从这张图开始 |
driving_audio | 1 | 驱动音频(wav/mp3),让人像跟随音频做口型/节奏 |
响应格式
{
"output": { "task_id": "f8ca39a0-6f4b-4ec2-99bf-8b9649d946c4", "task_status": "PENDING" },
"request_id": "..."
}
查询状态与下载视频
拿到task_id 后,按以下三步查询状态并下载 mp4:
- 轮询
GET /v1/tasks/{task_id}(带Authorization,查询不需要X-DashScope-Async头),每 5–10 秒一次(不要 < 3 秒),直到status变为completed。 - 状态取值:
submitted(排队)/in_progress(生成中,progress常停在 30% 属正常)/completed(成功)/failed(失败,看error)。 - 下载:从响应的
result_url直接 GET,不要带Authorization头(OSS 签名直链,带了反而 403);result_url默认 24 小时过期,务必尽快转存。
curl "https://api.apiyi.com/v1/tasks/f8ca39a0-6f4b-4ec2-99bf-8b9649d946c4" \
-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": "f8ca39a0-6f4b-4ec2-99bf-8b9649d946c4"
}
# 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="f8ca39a0-6f4b-4ec2-99bf-8b9649d946c4"
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 概览 · 异步调用流程。
授权
在 API易控制台获取的 API Key
请求头
异步处理开关,必须设置为 enable
可用选项:
enable 请求体
application/json
此页面对您有帮助吗?
⌘I