文生视频:根据文本提示词创建视频生成任务
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-t2v",
"input": {
"prompt": "黄昏海边的灯塔,镜头缓慢推进,海浪轻拍礁石,海鸟叫声,电影级光影,稳定运镜"
}
}
'import requests
url = "https://api.apiyi.com/wan/api/v1/services/aigc/video-generation/video-synthesis"
payload = {
"model": "wan2.7-t2v",
"input": { "prompt": "黄昏海边的灯塔,镜头缓慢推进,海浪轻拍礁石,海鸟叫声,电影级光影,稳定运镜" }
}
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-t2v', input: {prompt: '黄昏海边的灯塔,镜头缓慢推进,海浪轻拍礁石,海鸟叫声,电影级光影,稳定运镜'}})
};
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-t2v',
'input' => [
'prompt' => '黄昏海边的灯塔,镜头缓慢推进,海浪轻拍礁石,海鸟叫声,电影级光影,稳定运镜'
]
]),
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-t2v\",\n \"input\": {\n \"prompt\": \"黄昏海边的灯塔,镜头缓慢推进,海浪轻拍礁石,海鸟叫声,电影级光影,稳定运镜\"\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-t2v\",\n \"input\": {\n \"prompt\": \"黄昏海边的灯塔,镜头缓慢推进,海浪轻拍礁石,海鸟叫声,电影级光影,稳定运镜\"\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-t2v\",\n \"input\": {\n \"prompt\": \"黄昏海边的灯塔,镜头缓慢推进,海浪轻拍礁石,海鸟叫声,电影级光影,稳定运镜\"\n }\n}"
response = http.request(request)
puts response.read_body{
"output": {
"task_id": "c2e7570c-0af2-4eba-919f-3af3d1164a38",
"task_status": "PENDING"
},
"request_id": "a23b81b0-0c05-9972-a6c9-ee757400afdb"
}Wan2.7 影片生成(阿里雲)
Wan2.7 文生影片 API 參考
Wan2.7-t2v 文生影片 API 參考與線上除錯:純文本提示詞生成 2–15 秒影片,DashScope 非同步透傳端點。
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-t2v",
"input": {
"prompt": "黄昏海边的灯塔,镜头缓慢推进,海浪轻拍礁石,海鸟叫声,电影级光影,稳定运镜"
}
}
'import requests
url = "https://api.apiyi.com/wan/api/v1/services/aigc/video-generation/video-synthesis"
payload = {
"model": "wan2.7-t2v",
"input": { "prompt": "黄昏海边的灯塔,镜头缓慢推进,海浪轻拍礁石,海鸟叫声,电影级光影,稳定运镜" }
}
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-t2v', input: {prompt: '黄昏海边的灯塔,镜头缓慢推进,海浪轻拍礁石,海鸟叫声,电影级光影,稳定运镜'}})
};
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-t2v',
'input' => [
'prompt' => '黄昏海边的灯塔,镜头缓慢推进,海浪轻拍礁石,海鸟叫声,电影级光影,稳定运镜'
]
]),
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-t2v\",\n \"input\": {\n \"prompt\": \"黄昏海边的灯塔,镜头缓慢推进,海浪轻拍礁石,海鸟叫声,电影级光影,稳定运镜\"\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-t2v\",\n \"input\": {\n \"prompt\": \"黄昏海边的灯塔,镜头缓慢推进,海浪轻拍礁石,海鸟叫声,电影级光影,稳定运镜\"\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-t2v\",\n \"input\": {\n \"prompt\": \"黄昏海边的灯塔,镜头缓慢推进,海浪轻拍礁石,海鸟叫声,电影级光影,稳定运镜\"\n }\n}"
response = http.request(request)
puts response.read_body{
"output": {
"task_id": "c2e7570c-0af2-4eba-919f-3af3d1164a38",
"task_status": "PENDING"
},
"request_id": "a23b81b0-0c05-9972-a6c9-ee757400afdb"
}右側 Playground 可直接除錯:在 Authorization 填
Bearer sk-your-api-key,填好 model / input / parameters 後發起請求。提交成功會返回 task_id,後續輪詢與下載見下方說明。- 建立請求必須走
/wan/api/v1/services/aigc/video-generation/video-synthesis並帶請求頭X-DashScope-Async: enable,不要用/v1/videos。 duration必須是 整數(5不是"5");resolution寫 大寫720P。
程式碼示例
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-t2v",
"input": {
"prompt": "黃昏海邊的燈塔,鏡頭緩慢推進,海浪輕拍礁石,海鳥叫聲,電影級光影,穩定運鏡"
},
"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-t2v",
"input": {"prompt": "黃昏海邊的燈塔,鏡頭緩慢推進,海浪輕拍礁石,海鳥叫聲"},
"parameters": {"resolution": "720P", "duration": 5, "prompt_extend": True, "watermark": True},
}
resp = requests.post(url, json=body, headers=headers, timeout=30)
task_id = resp.json()["output"]["task_id"]
print("task_id:", task_id) # 拿到後輪詢 /v1/tasks/{task_id}
import json, urllib.request
BASE, KEY = "https://api.apiyi.com", "sk-your-api-key"
body = {
"model": "wan2.7-t2v",
"input": {"prompt": "黃昏海邊的燈塔,鏡頭緩慢推進,海浪輕拍礁石"},
"parameters": {"resolution": "720P", "duration": 5, "prompt_extend": True},
}
req = urllib.request.Request(
BASE + "/wan/api/v1/services/aigc/video-generation/video-synthesis",
data=json.dumps(body).encode(),
headers={"Authorization": f"Bearer {KEY}", "Content-Type": "application/json",
"X-DashScope-Async": "enable"},
method="POST",
)
print(json.loads(urllib.request.urlopen(req).read())["output"]["task_id"])
引數說明速查
| 引數 | 型別 | 必填 | 預設 | 說明 |
|---|---|---|---|---|
model | string | ✓ | — | 固定 wan2.7-t2v |
input.prompt | string | ✓ | — | 文本提示詞,建議描述場景、鏡頭運動、光線、風格 |
input.negative_prompt | string | — | 反向提示詞,≤500 字元 | |
parameters.resolution | string | 720P | 720P / 1080P(大寫) | |
parameters.ratio | string | 16:9 | 16:9 / 9:16 / 1:1 / 4:3 / 3:4 | |
parameters.duration | int | 5 | 2–15 秒整數 | |
parameters.prompt_extend | bool | true | 智慧改寫,推薦開啟 | |
parameters.watermark | bool | false | 右下角「AI 生成」水印 | |
parameters.seed | int | 隨機 | 0–2147483647,固定可復現 |
響應格式
建立成功返回task_id(不是影片本身):
{
"output": { "task_id": "c2e7570c-0af2-4eba-919f-3af3d1164a38", "task_status": "PENDING" },
"request_id": "a23b81b0-0c05-9972-a6c9-ee757400afdb"
}
查詢狀態與下載影片
拿到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/c2e7570c-0af2-4eba-919f-3af3d1164a38" \
-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": "c2e7570c-0af2-4eba-919f-3af3d1164a38"
}
# 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="c2e7570c-0af2-4eba-919f-3af3d1164a38"
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,否则报 current user api does not support synchronous calls
可用選項:
enable 主體
application/json
這個頁面有幫助嗎?
⌘I