Kling v3 視頻生成
curl --request POST \
--url https://toapis.com/v1/videos/generations \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "<string>",
"prompt": "<string>",
"mode": "<string>",
"duration": 123,
"aspect_ratio": "<string>",
"reference_images": [
"<string>"
],
"image_with_roles": [
{
"url": "<string>",
"role": "<string>"
}
],
"audio": true,
"metadata": {
"negative_prompt": "<string>",
"watermark": true
}
}
'import requests
url = "https://toapis.com/v1/videos/generations"
payload = {
"model": "<string>",
"prompt": "<string>",
"mode": "<string>",
"duration": 123,
"aspect_ratio": "<string>",
"reference_images": ["<string>"],
"image_with_roles": [
{
"url": "<string>",
"role": "<string>"
}
],
"audio": True,
"metadata": {
"negative_prompt": "<string>",
"watermark": True
}
}
headers = {
"Authorization": "<authorization>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: '<string>',
prompt: '<string>',
mode: '<string>',
duration: 123,
aspect_ratio: '<string>',
reference_images: ['<string>'],
image_with_roles: [{url: '<string>', role: '<string>'}],
audio: true,
metadata: {negative_prompt: '<string>', watermark: true}
})
};
fetch('https://toapis.com/v1/videos/generations', 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://toapis.com/v1/videos/generations",
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' => '<string>',
'prompt' => '<string>',
'mode' => '<string>',
'duration' => 123,
'aspect_ratio' => '<string>',
'reference_images' => [
'<string>'
],
'image_with_roles' => [
[
'url' => '<string>',
'role' => '<string>'
]
],
'audio' => true,
'metadata' => [
'negative_prompt' => '<string>',
'watermark' => true
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: application/json"
],
]);
$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://toapis.com/v1/videos/generations"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"mode\": \"<string>\",\n \"duration\": 123,\n \"aspect_ratio\": \"<string>\",\n \"reference_images\": [\n \"<string>\"\n ],\n \"image_with_roles\": [\n {\n \"url\": \"<string>\",\n \"role\": \"<string>\"\n }\n ],\n \"audio\": true,\n \"metadata\": {\n \"negative_prompt\": \"<string>\",\n \"watermark\": true\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
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://toapis.com/v1/videos/generations")
.header("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"mode\": \"<string>\",\n \"duration\": 123,\n \"aspect_ratio\": \"<string>\",\n \"reference_images\": [\n \"<string>\"\n ],\n \"image_with_roles\": [\n {\n \"url\": \"<string>\",\n \"role\": \"<string>\"\n }\n ],\n \"audio\": true,\n \"metadata\": {\n \"negative_prompt\": \"<string>\",\n \"watermark\": true\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://toapis.com/v1/videos/generations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"mode\": \"<string>\",\n \"duration\": 123,\n \"aspect_ratio\": \"<string>\",\n \"reference_images\": [\n \"<string>\"\n ],\n \"image_with_roles\": [\n {\n \"url\": \"<string>\",\n \"role\": \"<string>\"\n }\n ],\n \"audio\": true,\n \"metadata\": {\n \"negative_prompt\": \"<string>\",\n \"watermark\": true\n }\n}"
response = http.request(request)
puts response.read_bodyKling v3
Kling v3 視頻生成
使用官方 Kling v3 生成視頻,普通參考圖與首尾幀控制採用顯式區分語義
POST
/
v1
/
videos
/
generations
Kling v3 視頻生成
curl --request POST \
--url https://toapis.com/v1/videos/generations \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "<string>",
"prompt": "<string>",
"mode": "<string>",
"duration": 123,
"aspect_ratio": "<string>",
"reference_images": [
"<string>"
],
"image_with_roles": [
{
"url": "<string>",
"role": "<string>"
}
],
"audio": true,
"metadata": {
"negative_prompt": "<string>",
"watermark": true
}
}
'import requests
url = "https://toapis.com/v1/videos/generations"
payload = {
"model": "<string>",
"prompt": "<string>",
"mode": "<string>",
"duration": 123,
"aspect_ratio": "<string>",
"reference_images": ["<string>"],
"image_with_roles": [
{
"url": "<string>",
"role": "<string>"
}
],
"audio": True,
"metadata": {
"negative_prompt": "<string>",
"watermark": True
}
}
headers = {
"Authorization": "<authorization>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: '<string>',
prompt: '<string>',
mode: '<string>',
duration: 123,
aspect_ratio: '<string>',
reference_images: ['<string>'],
image_with_roles: [{url: '<string>', role: '<string>'}],
audio: true,
metadata: {negative_prompt: '<string>', watermark: true}
})
};
fetch('https://toapis.com/v1/videos/generations', 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://toapis.com/v1/videos/generations",
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' => '<string>',
'prompt' => '<string>',
'mode' => '<string>',
'duration' => 123,
'aspect_ratio' => '<string>',
'reference_images' => [
'<string>'
],
'image_with_roles' => [
[
'url' => '<string>',
'role' => '<string>'
]
],
'audio' => true,
'metadata' => [
'negative_prompt' => '<string>',
'watermark' => true
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: application/json"
],
]);
$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://toapis.com/v1/videos/generations"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"mode\": \"<string>\",\n \"duration\": 123,\n \"aspect_ratio\": \"<string>\",\n \"reference_images\": [\n \"<string>\"\n ],\n \"image_with_roles\": [\n {\n \"url\": \"<string>\",\n \"role\": \"<string>\"\n }\n ],\n \"audio\": true,\n \"metadata\": {\n \"negative_prompt\": \"<string>\",\n \"watermark\": true\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
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://toapis.com/v1/videos/generations")
.header("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"mode\": \"<string>\",\n \"duration\": 123,\n \"aspect_ratio\": \"<string>\",\n \"reference_images\": [\n \"<string>\"\n ],\n \"image_with_roles\": [\n {\n \"url\": \"<string>\",\n \"role\": \"<string>\"\n }\n ],\n \"audio\": true,\n \"metadata\": {\n \"negative_prompt\": \"<string>\",\n \"watermark\": true\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://toapis.com/v1/videos/generations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"mode\": \"<string>\",\n \"duration\": 123,\n \"aspect_ratio\": \"<string>\",\n \"reference_images\": [\n \"<string>\"\n ],\n \"image_with_roles\": [\n {\n \"url\": \"<string>\",\n \"role\": \"<string>\"\n }\n ],\n \"audio\": true,\n \"metadata\": {\n \"negative_prompt\": \"<string>\",\n \"watermark\": true\n }\n}"
response = http.request(request)
puts response.read_body- 異步任務接口,提交後返回任務 ID
- 支持文生視頻、圖生視頻、顯式首尾幀控制和有聲視頻
mode=std對應 720P,mode=pro對應 1080Paudio=true會生成有聲視頻,並按 Sound 價格計費duration支持3s、4s、5s、6s、7s、8s、9s、10s、11s、12s、13s、14s、15s
請傳入公網可訪問的圖片 URL。不要直接傳 base64 圖片數據;本地圖片請先使用 上傳圖片接口 獲取 URL。
認證
string
必填
所有接口均需要使用 Bearer Token 認證。
Authorization: Bearer YOUR_API_KEY
請求參數
string
必填
視頻生成模型名稱,固定爲
kling-v3。string
必填
視頻提示詞。建議描述主體、動作、場景、鏡頭語言和風格。
string
預設值:"std"
生成模式。
std- 標準模式,720Ppro- 專業模式,1080P
integer
預設值:"5"
視頻時長,單位秒。可選值:
3、4、5、6、7、8、9、10、11、12、13、14、15string
預設值:"16:9"
視頻寬高比。常用值:
16:9、9:16、1:1string[]
普通參考圖。
- 這裏只表示參考圖語義
- 不會再自動把第二張參考圖推斷爲尾幀
- 首尾幀請使用
image_with_roles顯式傳入
object[]
boolean
預設值:"false"
是否生成有聲視頻。
輸入規則
| 輸入形態 | 行爲 |
|---|---|
只有 reference_images | 普通參考圖 |
只有 image_with_roles 且角色僅有 first_frame / last_frame | 首尾幀控制 |
| 兩者混用,或 roles 中同時含 frame/reference 語義 | 混合模式 |
示例
文生視頻
{
"model": "kling-v3",
"prompt": "一隻金色的貓咪在陽光下的草地上奔跑,慢動作,電影質感",
"mode": "std",
"duration": 5,
"aspect_ratio": "16:9"
}
普通參考圖
{
"model": "kling-v3",
"prompt": "參考人物形象,讓角色輕輕微笑",
"reference_images": ["https://example.com/reference.jpg"],
"mode": "std",
"duration": 5
}
首尾幀控制
{
"model": "kling-v3",
"prompt": "城市從白天自然過渡到夜晚",
"image_with_roles": [
{ "url": "https://example.com/day.jpg", "role": "first_frame" },
{ "url": "https://example.com/night.jpg", "role": "last_frame" }
],
"mode": "pro",
"duration": 5
}
參考圖與首尾幀混合
{
"model": "kling-v3",
"prompt": "保持角色一致性,同時完成場景過渡",
"reference_images": ["https://example.com/character-reference.jpg"],
"image_with_roles": [
{ "url": "https://example.com/start-scene.jpg", "role": "first_frame" },
{ "url": "https://example.com/end-scene.jpg", "role": "last_frame" }
],
"mode": "pro",
"duration": 5
}
有聲視頻
{
"model": "kling-v3",
"prompt": "舞臺上的歌手正在演唱,觀衆歡呼,燈光閃爍",
"mode": "std",
"duration": 5,
"audio": true
}
視頻生成爲異步任務。提交後使用 獲取視頻任務狀態 查詢進度和結果。
⌘I