Tuyến theo mô hình
Tạo tác vụ chuyển văn bản thành video của Kling theo mô hình
Tạo video Kling từ Prompt văn bản bằng route dành riêng cho mô hình, sau đó truy xuất video bằng ID tác vụ.
POST
/
text-to-video
/
{model}
cURL
curl https://api.cometapi.com/text-to-video/kling-3.0-turbo \
-X POST \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
--data-raw '{
"prompt": "A paper boat drifts across a calm pond at sunrise.",
"settings": {
"resolution": "720p",
"aspect_ratio": "16:9",
"duration": 5
}
}'import os
import requests
response = requests.post(
"https://api.cometapi.com/text-to-video/kling-3.0-turbo",
headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
json={
"prompt": "A paper boat drifts across a calm pond at sunrise.",
"settings": {
"resolution": "720p",
"aspect_ratio": "16:9",
"duration": 5
},
},
)
response.raise_for_status()
print(response.json()["data"]["id"])
const response = await fetch(
"https://api.cometapi.com/text-to-video/kling-3.0-turbo",
{
method: "POST",
headers: {
Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
prompt: "A paper boat drifts across a calm pond at sunrise.",
settings: {
resolution: "720p",
aspect_ratio: "16:9",
duration: 5,
},
}),
},
);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log((await response.json()).data.id);
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.cometapi.com/text-to-video/{model}",
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([
'prompt' => 'A paper boat drifts across a calm pond at sunrise.'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"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://api.cometapi.com/text-to-video/{model}"
payload := strings.NewReader("{\n \"prompt\": \"A paper boat drifts across a calm pond at sunrise.\"\n}")
req, _ := http.NewRequest("POST", url, payload)
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.cometapi.com/text-to-video/{model}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"prompt\": \"A paper boat drifts across a calm pond at sunrise.\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/text-to-video/{model}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"prompt\": \"A paper boat drifts across a calm pond at sunrise.\"\n}"
response = http.request(request)
puts response.read_body{
"code": 0,
"message": "SUCCEED",
"data": {
"id": "example-task-id",
"status": "submitted"
}
}Gửi Prompt đến
Gửi body này đến
Lưu
POST /text-to-video/{model} để tạo tác vụ video. Phản hồi chứa id để bạn truy xuất kết quả.
Chọn mô hình
Đặt ID mô hình trong URL. Không thêm trường model vào body JSON.| ID mô hình | Độ phân giải | Thời lượng | Âm thanh |
|---|---|---|---|
kling-4.0 | 720p, 1080p | Số nguyên từ 3 đến 30 giây | Bỏ qua audio |
kling-3.0-turbo | 720p, 1080p | Số nguyên từ 3 đến 15 giây | Bỏ qua audio |
kling-3.0 | 720p, 1080p, 4k | Số nguyên từ 3 đến 15 giây | native hoặc off |
kling-2.6 | 720p, 1080p | 5 hoặc 10 giây | native hoặc off; dùng 1080p với native |
kling-2.5-turbo | 720p, 1080p | 5 hoặc 10 giây | Bỏ qua audio |
Tham số request
| Trường | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
Đường dẫn model | string | Có | ID mô hình trong URL. Chọn một ID từ bảng trên; không thêm ID này vào body của request. |
prompt | string | Có | Mô tả video cần tạo. |
settings.resolution | string | Không | Độ phân giải đầu ra theo hàng của mô hình đã chọn trong bảng trên. Mặc định là 720p. |
settings.aspect_ratio | string | Không | Tỷ lệ khung hình đầu ra: 21:9 (chỉ dành cho kling-4.0), 16:9, 9:16 hoặc 1:1. Mặc định là 16:9. |
settings.duration | integer | Không | Thời lượng video tính bằng giây theo hàng của mô hình đã chọn trong bảng trên. Mặc định là 10 cho kling-4.0 và 5 cho các mô hình khác. Gửi số nguyên, không phải chuỗi. |
settings.multi_shot | boolean | Không | Chỉ dành cho kling-3.0, giá trị mặc định chính thức là true. Đặt true để tạo nhiều cảnh hoặc false để tạo một cảnh, và đặt giá trị tường minh khi sử dụng trường này. |
settings.audio | string | Không | Đối với kling-3.0 hoặc kling-2.6, đặt native để tạo âm thanh hoặc off để không tạo âm thanh. Đặt giá trị tường minh khi sử dụng trường này. |
options.callback_url | string | Không | URL công khai nhận các cập nhật về tác vụ. |
options.external_task_id | string | Không | Mã định danh của bạn để liên kết tác vụ với ứng dụng. |
options.watermark_info | object | Không | Cấu hình hình mờ cho đầu ra. |
kling-4.0 không cung cấp tùy chọn settings.audio. Video của mô hình này có một bản âm thanh; hãy bỏ qua trường này thay vì gửi một giá trị mà mô hình không sử dụng.
Request sau tạo một video dài năm giây với kling-3.0-turbo:
{
"prompt": "A paper boat drifts across a calm pond at sunrise.",
"settings": {
"resolution": "720p",
"aspect_ratio": "16:9",
"duration": 5
}
}
https://api.cometapi.com/text-to-video/kling-3.0-turbo bằng khóa API CometAPI của bạn. Bảng mã OpenAPI cung cấp các request Shell, Python và JavaScript có cùng body.
Truy xuất video
Phản hồi tạo tác vụ có cấu trúc như sau:{
"code": 0,
"message": "SUCCEED",
"data": {
"id": "example-task-id",
"status": "submitted"
}
}
data.id. Sử dụng Lấy tác vụ Kling với ID đó cho đến khi tác vụ đạt trạng thái kết thúc. Đọc URL video từ mảng outputs của tác vụ.Tham số đường dẫn
Nội dung
application/json
Text-to-video request fields exposed by the CometAPI route. The model ID is a path parameter, not a body field.
Phản hồi
200 - application/json
The task was created. Use data.id to retrieve its status and video output.
Lần sửa đổi cuối 13 tháng 11, 2026
⌘I
cURL
curl https://api.cometapi.com/text-to-video/kling-3.0-turbo \
-X POST \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
--data-raw '{
"prompt": "A paper boat drifts across a calm pond at sunrise.",
"settings": {
"resolution": "720p",
"aspect_ratio": "16:9",
"duration": 5
}
}'import os
import requests
response = requests.post(
"https://api.cometapi.com/text-to-video/kling-3.0-turbo",
headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
json={
"prompt": "A paper boat drifts across a calm pond at sunrise.",
"settings": {
"resolution": "720p",
"aspect_ratio": "16:9",
"duration": 5
},
},
)
response.raise_for_status()
print(response.json()["data"]["id"])
const response = await fetch(
"https://api.cometapi.com/text-to-video/kling-3.0-turbo",
{
method: "POST",
headers: {
Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
prompt: "A paper boat drifts across a calm pond at sunrise.",
settings: {
resolution: "720p",
aspect_ratio: "16:9",
duration: 5,
},
}),
},
);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log((await response.json()).data.id);
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.cometapi.com/text-to-video/{model}",
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([
'prompt' => 'A paper boat drifts across a calm pond at sunrise.'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"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://api.cometapi.com/text-to-video/{model}"
payload := strings.NewReader("{\n \"prompt\": \"A paper boat drifts across a calm pond at sunrise.\"\n}")
req, _ := http.NewRequest("POST", url, payload)
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.cometapi.com/text-to-video/{model}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"prompt\": \"A paper boat drifts across a calm pond at sunrise.\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/text-to-video/{model}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"prompt\": \"A paper boat drifts across a calm pond at sunrise.\"\n}"
response = http.request(request)
puts response.read_body{
"code": 0,
"message": "SUCCEED",
"data": {
"id": "example-task-id",
"status": "submitted"
}
}