Text-to-video: create a video generation task from a text prompt
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": "A lighthouse on the seashore at dusk, the camera slowly pushing in, waves gently lapping the rocks, seabirds calling, cinematic lighting, steady camera work"
}
}
'import requests
url = "https://api.apiyi.com/wan/api/v1/services/aigc/video-generation/video-synthesis"
payload = {
"model": "wan2.7-t2v",
"input": { "prompt": "A lighthouse on the seashore at dusk, the camera slowly pushing in, waves gently lapping the rocks, seabirds calling, cinematic lighting, steady camera work" }
}
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: 'A lighthouse on the seashore at dusk, the camera slowly pushing in, waves gently lapping the rocks, seabirds calling, cinematic lighting, steady camera work'
}
})
};
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' => 'A lighthouse on the seashore at dusk, the camera slowly pushing in, waves gently lapping the rocks, seabirds calling, cinematic lighting, steady camera work'
]
]),
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\": \"A lighthouse on the seashore at dusk, the camera slowly pushing in, waves gently lapping the rocks, seabirds calling, cinematic lighting, steady camera work\"\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\": \"A lighthouse on the seashore at dusk, the camera slowly pushing in, waves gently lapping the rocks, seabirds calling, cinematic lighting, steady camera work\"\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\": \"A lighthouse on the seashore at dusk, the camera slowly pushing in, waves gently lapping the rocks, seabirds calling, cinematic lighting, steady camera work\"\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動画生成(Alibaba Cloud)
Wan2.7 テキストから動画への API リファレンス
Wan2.7-t2v テキストから動画 API リファレンスとライブプレイグラウンド: 純粋な prompt から DashScope の非同期パススルー endpoint を通じて 2-15 秒の動画を生成します。
POST
/
wan
/
api
/
v1
/
services
/
aigc
/
video-generation
/
video-synthesis
Text-to-video: create a video generation task from a text prompt
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": "A lighthouse on the seashore at dusk, the camera slowly pushing in, waves gently lapping the rocks, seabirds calling, cinematic lighting, steady camera work"
}
}
'import requests
url = "https://api.apiyi.com/wan/api/v1/services/aigc/video-generation/video-synthesis"
payload = {
"model": "wan2.7-t2v",
"input": { "prompt": "A lighthouse on the seashore at dusk, the camera slowly pushing in, waves gently lapping the rocks, seabirds calling, cinematic lighting, steady camera work" }
}
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: 'A lighthouse on the seashore at dusk, the camera slowly pushing in, waves gently lapping the rocks, seabirds calling, cinematic lighting, steady camera work'
}
})
};
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' => 'A lighthouse on the seashore at dusk, the camera slowly pushing in, waves gently lapping the rocks, seabirds calling, cinematic lighting, steady camera work'
]
]),
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\": \"A lighthouse on the seashore at dusk, the camera slowly pushing in, waves gently lapping the rocks, seabirds calling, cinematic lighting, steady camera work\"\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\": \"A lighthouse on the seashore at dusk, the camera slowly pushing in, waves gently lapping the rocks, seabirds calling, cinematic lighting, steady camera work\"\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\": \"A lighthouse on the seashore at dusk, the camera slowly pushing in, waves gently lapping the rocks, seabirds calling, cinematic lighting, steady camera work\"\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"
}右側のプレイグラウンドでは直接デバッグできます。
Bearer sk-your-api-key を Authorization に入れ、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": "A lighthouse on the seashore at dusk, the camera slowly pushing in, waves gently lapping the rocks, seabirds calling, cinematic lighting, steady camera work"
},
"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", # required when creating a task
}
body = {
"model": "wan2.7-t2v",
"input": {"prompt": "A lighthouse on the seashore at dusk, the camera slowly pushing in, waves gently lapping the rocks, seabirds calling"},
"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) # then poll /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": "A lighthouse on the seashore at dusk, the camera slowly pushing in, waves gently lapping the rocks"},
"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 | ✓ | — | テキスト prompt。シーン、カメラの動き、ライティング、スタイルを記述します |
input.negative_prompt | string | — | ネガティブ prompt、≤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 generated」の透かしを表示します | |
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 をダウンロードするために、次の 3 つの手順でステータスをポーリングしてください。
- ポーリング
GET /v1/tasks/{task_id}(Authorization付きで; クエリにはX-DashScope-Asyncヘッダーは不要です)を、5-10 秒ごと(3 秒未満は不可)に、statusがcompletedになるまで実行します。 - ステータス値:
submitted(queued)/in_progress(generating;progressが 30% 付近で止まっているのは正常です)/completed(success)/failed(errorを確認)。 - ダウンロード: 応答から
result_urlを直接 GET し、Authorizationヘッダーなしで(OSS 署名付きの直接リンクです — Auth を送ると 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 is an OSS signed direct link — do NOT send the Authorization header (it returns 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" # no Authorization
上記は、「task_id をすでに持っている」場合の簡易な確認/ダウンロード手順です。タイムアウトのフォールバックを含む完全なポーリングループと Python クライアントについては、Wan 概要 · 非同期呼び出しフロー を参照してください。
承認
The API Key obtained from the APIYI console
ヘッダー
Async processing switch; must be set to enable, otherwise it returns current user api does not support synchronous calls
利用可能なオプション:
enable ボディ
application/json
このページは役に立ちましたか?
⌘I