Tuyến theo mô hình
Tạo tác vụ chuyển hình ảnh thành video Kling theo mô hình
Tạo video Kling từ hình ảnh nguồn bằng tuyến dành riêng cho mô hình, sau đó truy xuất video bằng ID tác vụ.
POST
/
image-to-video
/
{model}
cURL
curl https://api.cometapi.com/image-to-video/kling-3.0-turbo \
-X POST \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
--data-raw '{
"contents": [
{
"type": "prompt",
"text": "The camera slowly moves closer to the scene."
},
{
"type": "first_frame",
"url": "https://raw.githubusercontent.com/ultralytics/yolov5/402e17ddf820996f51a191cbb798376e1144f069/data/images/zidane.jpg"
}
],
"settings": {
"resolution": "720p",
"duration": 5
}
}'
import os
import requests
response = requests.post(
"https://api.cometapi.com/image-to-video/kling-3.0-turbo",
headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
json={
"contents": [
{
"type": "prompt",
"text": "The camera slowly moves closer to the scene.",
},
{
"type": "first_frame",
"url": "https://raw.githubusercontent.com/ultralytics/yolov5/402e17ddf820996f51a191cbb798376e1144f069/data/images/zidane.jpg",
},
],
"settings": {
"resolution": "720p",
"duration": 5
},
},
)
response.raise_for_status()
print(response.json()["data"]["id"])
const response = await fetch(
"https://api.cometapi.com/image-to-video/kling-3.0-turbo",
{
method: "POST",
headers: {
Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
contents: [
{ type: "prompt", text: "The camera slowly moves closer to the scene." },
{
type: "first_frame",
url: "https://raw.githubusercontent.com/ultralytics/yolov5/402e17ddf820996f51a191cbb798376e1144f069/data/images/zidane.jpg",
},
],
settings: {
resolution: "720p",
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/image-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([
'contents' => [
[
'type' => 'prompt',
'text' => 'The camera slowly moves closer to the scene.'
],
[
'type' => 'first_frame',
'url' => 'https://raw.githubusercontent.com/ultralytics/yolov5/402e17ddf820996f51a191cbb798376e1144f069/data/images/zidane.jpg'
]
]
]),
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/image-to-video/{model}"
payload := strings.NewReader("{\n \"contents\": [\n {\n \"type\": \"prompt\",\n \"text\": \"The camera slowly moves closer to the scene.\"\n },\n {\n \"type\": \"first_frame\",\n \"url\": \"https://raw.githubusercontent.com/ultralytics/yolov5/402e17ddf820996f51a191cbb798376e1144f069/data/images/zidane.jpg\"\n }\n ]\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/image-to-video/{model}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"contents\": [\n {\n \"type\": \"prompt\",\n \"text\": \"The camera slowly moves closer to the scene.\"\n },\n {\n \"type\": \"first_frame\",\n \"url\": \"https://raw.githubusercontent.com/ultralytics/yolov5/402e17ddf820996f51a191cbb798376e1144f069/data/images/zidane.jpg\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/image-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 \"contents\": [\n {\n \"type\": \"prompt\",\n \"text\": \"The camera slowly moves closer to the scene.\"\n },\n {\n \"type\": \"first_frame\",\n \"url\": \"https://raw.githubusercontent.com/ultralytics/yolov5/402e17ddf820996f51a191cbb798376e1144f069/data/images/zidane.jpg\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"code": 0,
"message": "SUCCEED",
"data": {
"id": "example-task-id",
"status": "submitted"
}
}Gửi hình ảnh nguồn đến
Thay URL hình ảnh bằng URL công khai hoặc dữ liệu JPG/PNG được mã hóa Base64 của ảnh nguồn khi bạn sử dụng ảnh khác. Gửi nội dung này đến
Lưu
POST /image-to-video/{model} để tạo tác vụ video. Bạn có thể thêm Prompt để mô tả chuyển động. Phản hồi chứa id mà bạn dùng để 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 phần nội dung 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; sử dụng 1080p với native |
kling-2.5-turbo | 720p, 1080p | 5 hoặc 10 giây | Bỏ qua audio |
kling-4.0 chấp nhận first_frame, middle_frame và last_frame; hãy thêm first_frame khi sử dụng last_frame. kling-3.0-turbo chỉ chấp nhận first_frame. kling-2.5-turbo,
kling-3.0, và kling-2.6 cũng hỗ trợ last_frame; hãy thêm
first_frame cùng với giá trị đó. Đối với kling-2.5-turbo và kling-2.6,
tổ hợp khung hình đầu và cuối yêu cầu 1080p.
Tham số yêu cầu
Đặt từng đầu vào trongcontents. Một mục prompt sử dụng text; một mục khung hình sử dụng url. Đối với hình ảnh, cung cấp URL có thể truy cập công khai hoặc dữ liệu JPG hoặc PNG được mã hóa Base64.
| Trường | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
Đường dẫn model | chuỗi | Có | ID mô hình trong URL. Chọn một ID từ bảng trên; không thêm ID đó vào nội dung yêu cầu. |
contents | mảng | Có | Các mục đầu vào. Bao gồm một hình ảnh first_frame; thêm một mục prompt hoặc một hình ảnh last_frame được mô hình hỗ trợ khi cần. |
contents[].type | chuỗi | Có | prompt, first_frame, hoặc last_frame. Bao gồm first_frame khi sử dụng last_frame; mô hình được chọn quyết định liệu có thể sử dụng last_frame hay không. |
contents[].text | chuỗi | Đối với mục prompt | Văn bản mô tả chuyển động. |
contents[].url | chuỗi | Đối với mục khung hình | URL hình ảnh công khai hoặc dữ liệu JPG hoặc PNG được mã hóa Base64. |
settings.resolution | chuỗi | Không | Độ phân giải đầu ra theo hàng của mô hình được chọn trong bảng trên. Giá trị mặc định là 720p. |
settings.duration | số nguyên | Không | Độ dài video tính bằng giây theo hàng của mô hình được chọn trong bảng trên. Giá trị mặc định là 10 đối với kling-4.0 và 5 đối với các mô hình khác. Gửi một số nguyên, không phải chuỗi. |
settings.multi_shot | boolean | Không | Chỉ đối với kling-3.0, giá trị mặc định chính thức là true. Đặt true cho nhiều cảnh quay hoặc false cho một cảnh quay, và đặt giá trị tường minh khi sử dụng trường này. |
settings.audio | chuỗi | 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 | chuỗi | Không | URL công khai nhận các bản cập nhật tác vụ. |
options.external_task_id | chuỗi | Không | Mã định danh của bạn để đối chiếu tác vụ với ứng dụng. |
options.watermark_info | đối tượng | 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ó chứa 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 sẽ bỏ qua.
Yêu cầu sau tạo chuyển động cho một ảnh nguồn thành video dài năm giây:
{
"contents": [
{
"type": "prompt",
"text": "The camera slowly moves closer to the scene."
},
{
"type": "first_frame",
"url": "https://raw.githubusercontent.com/ultralytics/yolov5/402e17ddf820996f51a191cbb798376e1144f069/data/images/zidane.jpg"
}
],
"settings": {
"resolution": "720p",
"duration": 5
}
}
https://api.cometapi.com/image-to-video/kling-3.0-turbo cùng với khóa API CometAPI của bạn. Bảng mã OpenAPI cung cấp các yêu cầu Shell, Python và JavaScript có cùng nội dung.
Truy xuất video
Phản hồi từ yêu cầu tạo có dạng 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. Lấy URL video từ mảng outputs của tác vụ.Tham số đường dẫn
Nội dung
application/json
Image-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/image-to-video/kling-3.0-turbo \
-X POST \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
--data-raw '{
"contents": [
{
"type": "prompt",
"text": "The camera slowly moves closer to the scene."
},
{
"type": "first_frame",
"url": "https://raw.githubusercontent.com/ultralytics/yolov5/402e17ddf820996f51a191cbb798376e1144f069/data/images/zidane.jpg"
}
],
"settings": {
"resolution": "720p",
"duration": 5
}
}'
import os
import requests
response = requests.post(
"https://api.cometapi.com/image-to-video/kling-3.0-turbo",
headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
json={
"contents": [
{
"type": "prompt",
"text": "The camera slowly moves closer to the scene.",
},
{
"type": "first_frame",
"url": "https://raw.githubusercontent.com/ultralytics/yolov5/402e17ddf820996f51a191cbb798376e1144f069/data/images/zidane.jpg",
},
],
"settings": {
"resolution": "720p",
"duration": 5
},
},
)
response.raise_for_status()
print(response.json()["data"]["id"])
const response = await fetch(
"https://api.cometapi.com/image-to-video/kling-3.0-turbo",
{
method: "POST",
headers: {
Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
contents: [
{ type: "prompt", text: "The camera slowly moves closer to the scene." },
{
type: "first_frame",
url: "https://raw.githubusercontent.com/ultralytics/yolov5/402e17ddf820996f51a191cbb798376e1144f069/data/images/zidane.jpg",
},
],
settings: {
resolution: "720p",
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/image-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([
'contents' => [
[
'type' => 'prompt',
'text' => 'The camera slowly moves closer to the scene.'
],
[
'type' => 'first_frame',
'url' => 'https://raw.githubusercontent.com/ultralytics/yolov5/402e17ddf820996f51a191cbb798376e1144f069/data/images/zidane.jpg'
]
]
]),
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/image-to-video/{model}"
payload := strings.NewReader("{\n \"contents\": [\n {\n \"type\": \"prompt\",\n \"text\": \"The camera slowly moves closer to the scene.\"\n },\n {\n \"type\": \"first_frame\",\n \"url\": \"https://raw.githubusercontent.com/ultralytics/yolov5/402e17ddf820996f51a191cbb798376e1144f069/data/images/zidane.jpg\"\n }\n ]\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/image-to-video/{model}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"contents\": [\n {\n \"type\": \"prompt\",\n \"text\": \"The camera slowly moves closer to the scene.\"\n },\n {\n \"type\": \"first_frame\",\n \"url\": \"https://raw.githubusercontent.com/ultralytics/yolov5/402e17ddf820996f51a191cbb798376e1144f069/data/images/zidane.jpg\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/image-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 \"contents\": [\n {\n \"type\": \"prompt\",\n \"text\": \"The camera slowly moves closer to the scene.\"\n },\n {\n \"type\": \"first_frame\",\n \"url\": \"https://raw.githubusercontent.com/ultralytics/yolov5/402e17ddf820996f51a191cbb798376e1144f069/data/images/zidane.jpg\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"code": 0,
"message": "SUCCEED",
"data": {
"id": "example-task-id",
"status": "submitted"
}
}