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": "happyhorse-1.1-t2v",
"input": {
"prompt": "A cat running across a meadow, bright sunshine, camera following, cinematic lighting"
}
}
'import requests
url = "https://api.apiyi.com/wan/api/v1/services/aigc/video-generation/video-synthesis"
payload = {
"model": "happyhorse-1.1-t2v",
"input": { "prompt": "A cat running across a meadow, bright sunshine, camera following, cinematic lighting" }
}
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: 'happyhorse-1.1-t2v',
input: {
prompt: 'A cat running across a meadow, bright sunshine, camera following, cinematic lighting'
}
})
};
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' => 'happyhorse-1.1-t2v',
'input' => [
'prompt' => 'A cat running across a meadow, bright sunshine, camera following, cinematic lighting'
]
]),
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\": \"happyhorse-1.1-t2v\",\n \"input\": {\n \"prompt\": \"A cat running across a meadow, bright sunshine, camera following, cinematic lighting\"\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\": \"happyhorse-1.1-t2v\",\n \"input\": {\n \"prompt\": \"A cat running across a meadow, bright sunshine, camera following, cinematic lighting\"\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\": \"happyhorse-1.1-t2v\",\n \"input\": {\n \"prompt\": \"A cat running across a meadow, bright sunshine, camera following, cinematic lighting\"\n }\n}"
response = http.request(request)
puts response.read_body{
"output": {
"task_id": "hh-12ab34cd-...",
"task_status": "PENDING"
},
"request_id": "..."
}HappyHorse動画生成(Alibaba Cloud)
HappyHorse テキストから動画 API リファレンス
HappyHorse-1.1-t2v のテキストから動画 API リファレンスとオンラインデバッグ: 純粋な text prompt から動画を生成する、DashScope の非同期パススルー エンドポイントです。
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": "happyhorse-1.1-t2v",
"input": {
"prompt": "A cat running across a meadow, bright sunshine, camera following, cinematic lighting"
}
}
'import requests
url = "https://api.apiyi.com/wan/api/v1/services/aigc/video-generation/video-synthesis"
payload = {
"model": "happyhorse-1.1-t2v",
"input": { "prompt": "A cat running across a meadow, bright sunshine, camera following, cinematic lighting" }
}
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: 'happyhorse-1.1-t2v',
input: {
prompt: 'A cat running across a meadow, bright sunshine, camera following, cinematic lighting'
}
})
};
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' => 'happyhorse-1.1-t2v',
'input' => [
'prompt' => 'A cat running across a meadow, bright sunshine, camera following, cinematic lighting'
]
]),
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\": \"happyhorse-1.1-t2v\",\n \"input\": {\n \"prompt\": \"A cat running across a meadow, bright sunshine, camera following, cinematic lighting\"\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\": \"happyhorse-1.1-t2v\",\n \"input\": {\n \"prompt\": \"A cat running across a meadow, bright sunshine, camera following, cinematic lighting\"\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\": \"happyhorse-1.1-t2v\",\n \"input\": {\n \"prompt\": \"A cat running across a meadow, bright sunshine, camera following, cinematic lighting\"\n }\n}"
response = http.request(request)
puts response.read_body{
"output": {
"task_id": "hh-12ab34cd-...",
"task_status": "PENDING"
},
"request_id": "..."
}右側の Playground で直接デバッグできます。Authorization に
Bearer sk-your-api-key を入力し、model / input / parameters を設定してから、リクエストを送信してください。送信が成功すると task_id が返されます。ポーリングとダウンロードについては下記を参照してください。このページでは、
happyhorse-1.1-t2v(Text-to-Video)の create エンドポイントを扱います。必要なのはテキスト prompt のみです。非同期フロー全体、ステータステーブル、Python クライアントについては、HappyHorse の概要を参照してください。- create リクエストは、リクエストヘッダー
X-DashScope-Async: enable付きで/wan/api/v1/services/aigc/video-generation/video-synthesisに送信する必要があります。/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": "happyhorse-1.1-t2v",
"input": {
"prompt": "A cat running across a meadow, bright sunshine, camera following, cinematic lighting"
},
"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 for creating a task
}
body = {
"model": "happyhorse-1.1-t2v",
"input": {"prompt": "A cat running across a meadow, bright sunshine, camera following"},
"parameters": {"resolution": "720P", "duration": 5, "prompt_extend": True, "watermark": True},
}
resp = requests.post(url, json=body, headers=headers, timeout=30)
print("task_id:", resp.json()["output"]["task_id"])
import json, urllib.request
BASE, KEY = "https://api.apiyi.com", "sk-your-api-key"
body = {
"model": "happyhorse-1.1-t2v",
"input": {"prompt": "A cat running across a meadow, bright sunshine"},
"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"])
パラメータ クイック リファレンス
| Parameter | Type | Required | Default | Notes |
|---|---|---|---|---|
model | string | ✓ | — | happyhorse-1.1-t2v に固定 |
input.prompt | string | ✓ | — | テキスト prompt。シーン、カメラの動き、照明、スタイルを説明してください |
parameters.resolution | string | 720P | 720P / 1080P(大文字) | |
parameters.duration | int | 5 | 2〜15秒の整数 | |
parameters.prompt_extend | bool | true | スマートな書き換え、オン推奨 | |
parameters.watermark | bool | false | 右下に「AI Generated」のウォーターマーク | |
parameters.seed | int | random | 0〜2147483647、再現性のために固定 |
レスポンス形式
作成が成功すると、task_id が返されます(動画そのものではありません):
{
"output": { "task_id": "...", "task_status": "PENDING" },
"request_id": "..."
}
送信後は、
GET /v1/tasks/{task_id} を ポーリング して status: "completed" になるまで待ち、その後、レスポンス内の result_url から mp4 をダウンロードします。ダウンロード時は Authorization ヘッダーを含めないでください(署名付き OSS 直接リンクです)。また、result_url はデフォルトで 24 時間後に期限切れになります。完全なポーリングループは HappyHorse Overview · Async Call Flow を参照してください。承認
The API Key obtained from the APIYI Console
ヘッダー
Async processing switch, must be set to enable
利用可能なオプション:
enable ボディ
application/json
このページは役に立ちましたか?
⌘I