万相 3.0 视频生成(DashScope 官方协议)
curl --request POST \
--globoff \
--url 'https://api.example.com/{{llmApiOrigin}}/wan/api/v1/services/aigc/video-generation/video-synthesis' \
--header 'Authorization: <authorization>'import requests
url = "https://api.example.com/{{llmApiOrigin}}/wan/api/v1/services/aigc/video-generation/video-synthesis"
headers = {"Authorization": "<authorization>"}
response = requests.post(url, headers=headers)
print(response.text)const options = {method: 'POST', headers: {Authorization: '<authorization>'}};
fetch('https://api.example.com/{{llmApiOrigin}}/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.example.com/{{llmApiOrigin}}/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_HTTPHEADER => [
"Authorization: <authorization>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/{{llmApiOrigin}}/wan/api/v1/services/aigc/video-generation/video-synthesis"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("Authorization", "<authorization>")
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.example.com/{{llmApiOrigin}}/wan/api/v1/services/aigc/video-generation/video-synthesis")
.header("Authorization", "<authorization>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/{{llmApiOrigin}}/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["Authorization"] = '<authorization>'
response = http.request(request)
puts response.read_body视频系列
万相 3.0 视频生成(DashScope 官方协议)
通义万相 Wan 3.0 官方协议入口:文生视频、图生视频与异步任务查询
POST
{llmApiOrigin}
/
wan
/
api
/
v1
/
services
/
aigc
/
video-generation
/
video-synthesis
万相 3.0 视频生成(DashScope 官方协议)
curl --request POST \
--globoff \
--url 'https://api.example.com/{{llmApiOrigin}}/wan/api/v1/services/aigc/video-generation/video-synthesis' \
--header 'Authorization: <authorization>'import requests
url = "https://api.example.com/{{llmApiOrigin}}/wan/api/v1/services/aigc/video-generation/video-synthesis"
headers = {"Authorization": "<authorization>"}
response = requests.post(url, headers=headers)
print(response.text)const options = {method: 'POST', headers: {Authorization: '<authorization>'}};
fetch('https://api.example.com/{{llmApiOrigin}}/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.example.com/{{llmApiOrigin}}/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_HTTPHEADER => [
"Authorization: <authorization>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/{{llmApiOrigin}}/wan/api/v1/services/aigc/video-generation/video-synthesis"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("Authorization", "<authorization>")
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.example.com/{{llmApiOrigin}}/wan/api/v1/services/aigc/video-generation/video-synthesis")
.header("Authorization", "<authorization>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/{{llmApiOrigin}}/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["Authorization"] = '<authorization>'
response = http.request(request)
puts response.read_body简介
万相入口以阿里云百炼 DashScope 视频生成协议对外提供服务,支持 Wan 3.0 系列模型的文生视频、首帧 / 首尾帧生视频,以及参考图、参考视频、参考音频驱动。POST /wan/api/v1/services/aigc/video-generation/video-synthesis 提交任务
GET /wan/api/v1/tasks/{task_id} 查询任务
/wan)。使用官方 DashScope SDK 时,把 SDK 的 base_url 指向 https://api.shengmoai.com/wan 即可。
视频生成是异步任务:提交接口返回 HTTP 200 只代表任务已被接受,不代表视频已经生成完成。请轮询查询接口,直到SUCCEEDED或FAILED。
认证
支持模型
| 模型 | 说明 |
|---|---|
wan3.0-video | 万相 3.0 视频生成 |
wan3.0-video-prime | 万相 3.0 视频生成(高速版) |
模型是否可用取决于服务端渠道配置与上游账号开通情况。上游账号未开通某个模型时,调用可能返回模型不存在 / 未开通类错误。
提交任务
POST/wan/api/v1/services/aigc/video-generation/video-synthesis
文生视频
curl -X POST "https://api.shengmoai.com/wan/api/v1/services/aigc/video-generation/video-synthesis" \
-H "Authorization: Bearer sk-xxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "wan3.0-video",
"input": {
"prompt": "一只小猫在月光下的屋顶上奔跑"
},
"parameters": {
"resolution": "1080P",
"ratio": "16:9",
"duration": 5
}
}'
图生视频(首帧驱动)
curl -X POST "https://api.shengmoai.com/wan/api/v1/services/aigc/video-generation/video-synthesis" \
-H "Authorization: Bearer sk-xxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "wan3.0-video-prime",
"input": {
"prompt": "让画面中的花朵绽放",
"media": [
{ "type": "first_frame", "url": "https://example.com/first-frame.png" }
]
},
"parameters": {
"resolution": "720P",
"duration": 5,
"audio": true
}
}'
请求参数
顶层结构:| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | wan3.0-video 或 wan3.0-video-prime |
input | object | 是 | prompt 与 media 至少提供其一 |
parameters | object | 否 | 生成参数 |
input.prompt:文本提示词,与 media 至少其一;允许只传 media(如纯参考图 / 视频驱动)。
input.media[] 类型与数量上限(超限直接返回 400):
type | 上限 | 说明 |
|---|---|---|
first_frame | 1 | 首帧图 |
last_frame | 1 | 尾帧图 |
reference_image | 10 | 参考图 |
reference_video | 5 | 参考视频(总时长以官方限制为准) |
reference_audio | 5 | 参考音频(总时长以官方限制为准) |
file | 1 | 素材文件,与 link 互斥 |
link | 1 | 素材链接,与 file 互斥 |
media 项为 { "type": "...", "url": "..." },url 为非空字符串(公网 URL)。
parameters 字段:
| 字段 | 类型 | 说明 |
|---|---|---|
resolution | string | 1080P / 720P / 480P(大小写不敏感) |
ratio | string | adaptive / 16:9 / 4:3 / 1:1 / 3:4 / 9:16 |
duration | integer | 生成时长,1–30 秒;影响预扣额度,完成后按实测时长结算 |
audio | boolean | 是否生成音频 |
prompt_extend | boolean | 提示词改写开关 |
watermark | boolean | 水印开关 |
seed | integer | 随机种子,0–2147483647 |
提交响应
{
"request_id": "task_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"output": {
"task_id": "task_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"task_status": "PENDING"
}
}
output.task_id 是对外任务 ID(task_ 开头),后续查询使用它。该 ID 与上游内部任务 ID 不同,仅用于本网关。
查询任务
GET/wan/api/v1/tasks/{task_id}
curl "https://api.shengmoai.com/wan/api/v1/tasks/task_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
-H "Authorization: Bearer sk-xxxxxxxxxx"
进行中
{
"request_id": "task_XXXX...",
"output": {
"task_id": "task_XXXX...",
"task_status": "RUNNING"
}
}
成功
{
"request_id": "task_XXXX...",
"output": {
"task_id": "task_XXXX...",
"task_status": "SUCCEEDED",
"video_url": "https://example.com/result.mp4"
},
"usage": {
"input_video_duration": 2,
"output_video_duration": 5,
"duration": 7,
"SR": "1080P",
"video_count": 1
}
}
失败
{
"request_id": "task_XXXX...",
"output": {
"task_id": "task_XXXX...",
"task_status": "FAILED"
},
"error": {
"type": "video_generation_error",
"message": "上游返回的失败原因"
}
}
状态取值
| 状态 | 说明 |
|---|---|
PENDING | 已受理,排队中(含首次状态同步前的窗口期) |
RUNNING | 生成中 |
SUCCEEDED | 生成完成,取 output.video_url |
FAILED | 生成失败 |
CANCELED | 任务被取消 |
usage 字段(成功时返回)
| 字段 | 说明 |
|---|---|
duration | 实测计费总秒数(输入素材 + 输出视频) |
SR | 实际生成分辨率档位(1080P / 720P / 480P) |
input_video_duration / output_video_duration | 输入 / 输出视频秒数 |
video_count | 视频条数(当前恒为 1) |
轮询建议间隔 5–10 秒;任务通常几十秒到几分钟完成。video_url有时效性,请在拿到SUCCEEDED后尽快下载转存,也可以使用视频内容获取接口代理取回。
计费说明
- 按「秒 × 分辨率档位」计费,档位倍率与官方价目一致(480P / 720P / 1080P = 1 : 2 : 4,有声 / 无声同价);具体单价以平台模型价格配置为准;
- 提交时按请求的
duration(缺省按 5 秒估)与resolution(缺省按 1080P 档估)预扣; - 任务完成后按
usage.duration实测秒数与实际档位重算,多退少补;未填duration/resolution时的预扣偏差同样由差额结算纠正; - 生成失败的任务全额退款。
错误处理
| 场景 | HTTP | 响应形状 |
|---|---|---|
| 本地参数校验失败(模型名 / media 上限 / duration / 枚举等) | 400 | { "error": { "type": "invalid_request_error", "code": "missing_parameter", "message": "具体原因" } } |
| 提交被上游 / 网关拒绝 | 相应状态码 | { "code": "...", "message": "..." }(任务错误格式) |
| 查询的任务不存在 | 相应状态码 | 任务错误格式 |
| 任务生成失败 | 查询返回 200 | 终态 FAILED / CANCELED,错误原因见 error.message |
相关页面
视频生成总览
异步流程与各入口选择
统一视频接口
多模型统一的 /v1/video/generations 入口
