Tuyến theo mô hình
Lấy một tác vụ model-route Kling
Lấy trạng thái và đầu ra video của một tác vụ model-route Kling theo ID tác vụ.
GET
/
tasks
cURL
task_id="<task_id>"
curl "https://api.cometapi.com/tasks?task_ids=${task_id}" \
-H "Authorization: Bearer $COMETAPI_KEY"import os
import requests
task_id = "<task_id>"
response = requests.get(
"https://api.cometapi.com/tasks",
params={"task_ids": task_id},
headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
)
response.raise_for_status()
payload = response.json()
task = payload.get("data", payload)
if isinstance(task, list):
task = task[0]
print(task["status"], task.get("outputs", []))
const taskId = "<task_id>";
const url = new URL("https://api.cometapi.com/tasks");
url.searchParams.set("task_ids", taskId);
const response = await fetch(url, {
headers: { Authorization: `Bearer ${process.env.COMETAPI_KEY}` },
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const payload = await response.json();
const data = payload.data ?? payload;
const task = Array.isArray(data) ? data[0] : data;
console.log(task.status, task.outputs ?? []);
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.cometapi.com/tasks",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.cometapi.com/tasks"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.cometapi.com/tasks")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/tasks")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"code": 0,
"message": "SUCCEED",
"data": [
{
"id": "<task_id>",
"status": "submitted"
}
]
}Sử dụng endpoint này sau khi gửi yêu cầu tạo model-route Kling. Lưu
Để truy xuất một tác vụ, thay thế
Ngay sau khi tạo, phản hồi chứa tác vụ đã gửi:
Lưu video đã hoàn tất vào kho lưu trữ của riêng bạn nếu cần giữ lại video sau thời gian URL được trả về còn khả dụng.
data.id từ phản hồi tạo và truyền ID đó dưới dạng task_ids.
Tham số yêu cầu
| Tham số | Bắt buộc | Mô tả |
|---|---|---|
task_ids | Có | ID tác vụ được trả về bởi yêu cầu tạo model-route trong data.id. |
<task_id> bằng giá trị data.id từ phản hồi tạo:
task_id="<task_id>"
curl "https://api.cometapi.com/tasks?task_ids=${task_id}" \
-H "Authorization: Bearer $COMETAPI_KEY"
{
"code": 0,
"message": "SUCCEED",
"data": [
{
"id": "<task_id>",
"status": "submitted"
}
]
}
Đọc kết quả
Đọc tác vụ từdata[0] và tiếp tục truy vấn cho đến khi status của tác vụ ở trạng thái kết thúc. Khi trạng thái là succeeded, hãy đọc URL video từ mảng outputs của tác vụ đó. Một số phản hồi tương thích Comet được quan sát trả về một đối tượng tác vụ thuần hoặc chứa status cấp cao nhất; đây là các dạng tương thích, không phải envelope chuẩn. Khi có data, hãy dùng data[0].status.
Một tác vụ đã hoàn tất có cấu trúc phản hồi như sau:
{
"code": 0,
"message": "SUCCEED",
"data": [
{
"id": "<task_id>",
"status": "succeeded",
"outputs": [
{
"type": "video",
"url": "https://media.example.com/video.mp4",
"duration": "5.041"
}
]
}
]
}
| Trường | Mô tả |
|---|---|
id | ID tác vụ từ phản hồi tạo. |
status | Trạng thái hiện tại của tác vụ. Tiếp tục truy vấn cho đến khi tác vụ đạt trạng thái kết thúc. |
message | Chi tiết tác vụ được trả về khi có sẵn. |
outputs[].type | Loại nội dung đa phương tiện đầu ra. Chọn một mục có type: video. |
outputs[].url | URL video để tải xuống hoặc lưu trữ khi tác vụ thành công. |
outputs[].duration | Thời lượng video tính bằng giây khi được trả về. |
Tham số truy vấn
Phản hồi
200 - application/json
The task state and available outputs are returned in the data array.
Canonical task response for the CometAPI route. Read the selected task from data[0]; a bare task object is a compatibility form.
Lần sửa đổi cuối 25 tháng 9, 2026
⌘I
cURL
task_id="<task_id>"
curl "https://api.cometapi.com/tasks?task_ids=${task_id}" \
-H "Authorization: Bearer $COMETAPI_KEY"import os
import requests
task_id = "<task_id>"
response = requests.get(
"https://api.cometapi.com/tasks",
params={"task_ids": task_id},
headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
)
response.raise_for_status()
payload = response.json()
task = payload.get("data", payload)
if isinstance(task, list):
task = task[0]
print(task["status"], task.get("outputs", []))
const taskId = "<task_id>";
const url = new URL("https://api.cometapi.com/tasks");
url.searchParams.set("task_ids", taskId);
const response = await fetch(url, {
headers: { Authorization: `Bearer ${process.env.COMETAPI_KEY}` },
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const payload = await response.json();
const data = payload.data ?? payload;
const task = Array.isArray(data) ? data[0] : data;
console.log(task.status, task.outputs ?? []);
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.cometapi.com/tasks",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.cometapi.com/tasks"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.cometapi.com/tasks")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/tasks")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"code": 0,
"message": "SUCCEED",
"data": [
{
"id": "<task_id>",
"status": "submitted"
}
]
}