Kling
建立 Kling 圖生影片任務
透過 CometAPI POST /kling/v1/videos/image2video,將單張圖片轉換為 Kling 影片,並支援非同步任務建立與依 task ID 追蹤進度。
POST
/
kling
/
v1
/
videos
/
image2video
cURL
curl https://api.cometapi.com/kling/v1/videos/image2video \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"image": "https://your-image-host/source.jpg",
"prompt": "A cinematic slow push-in on the subject",
"model_name": "kling-v3",
"mode": "pro",
"duration": "5",
"sound": "off"
}'import os
import requests
response = requests.post(
"https://api.cometapi.com/kling/v1/videos/image2video",
headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
json={
"image": "https://your-image-host/source.jpg",
"prompt": "A cinematic slow push-in on the subject",
"model_name": "kling-v3",
"mode": "pro",
"duration": "5",
"sound": "off"
},
)
result = response.json()
print(result.get("code"), result.get("data", {}).get("task_id"))
const response = await fetch("https://api.cometapi.com/kling/v1/videos/image2video", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"image": "https://your-image-host/source.jpg",
"prompt": "A cinematic slow push-in on the subject",
"model_name": "kling-v3",
"mode": "pro",
"duration": "5",
"sound": "off"
}),
});
const result = await response.json();
console.log(result.code, result.data?.task_id);
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.cometapi.com/kling/v1/videos/image2video",
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([
'image' => 'https://your-image-host/source.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/kling/v1/videos/image2video"
payload := strings.NewReader("{\n \"image\": \"https://your-image-host/source.jpg\"\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/kling/v1/videos/image2video")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"image\": \"https://your-image-host/source.jpg\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/kling/v1/videos/image2video")
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 \"image\": \"https://your-image-host/source.jpg\"\n}"
response = http.request(request)
puts response.read_body{
"code": 0,
"message": "success",
"data": {
"task_id": "2032273942220931072",
"task_status": "submitted",
"task_info": {},
"created_at": 1773366840306,
"updated_at": 1773366840306
}
}使用此端點可將一張來源圖片製作成動畫並生成 Kling 影片。
呼叫前準備
- 提供一個公開圖片 URL 或一個 base64 圖片字串
- 使用符合 Kling 像素要求的圖片;過小的縮圖會被生成任務拒絕
- 先從預設的
kling-v2-6範例開始,當你需要不同模型路線時,再從 OpenAPI enum 中選擇其他model_name - 保持第一次請求簡單:一張輸入圖片、一個 prompt、無尾幀、無動作遮罩
- 當你需要可控的局部動作時,使用
dynamic_masks作為由遮罩與軌跡物件組成的陣列 - 對於支援生成聲音的模型路線,第一個請求可使用
sound: off來實現可重現且無音訊的結果
模型命名
在此端點上請使用一般的 Kling 影片 model ID。Omni model ID 請保留給 Omni Video。任務流程
1
提交圖生影片請求
建立任務並儲存回傳的 Kling
task_id。2
輪詢任務
接著使用 取得 Kling 任務 持續追蹤任務狀態,直到輸出準備完成。
3
儲存結果
如果你需要在供應商交付 URL 的保留期限之外繼續保存資產,請持久化儲存已完成的成品。
完整參數參考請見官方 Kling 文件。
主體
application/json
最後修改於 2026年6月26日
⌘I
cURL
curl https://api.cometapi.com/kling/v1/videos/image2video \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"image": "https://your-image-host/source.jpg",
"prompt": "A cinematic slow push-in on the subject",
"model_name": "kling-v3",
"mode": "pro",
"duration": "5",
"sound": "off"
}'import os
import requests
response = requests.post(
"https://api.cometapi.com/kling/v1/videos/image2video",
headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
json={
"image": "https://your-image-host/source.jpg",
"prompt": "A cinematic slow push-in on the subject",
"model_name": "kling-v3",
"mode": "pro",
"duration": "5",
"sound": "off"
},
)
result = response.json()
print(result.get("code"), result.get("data", {}).get("task_id"))
const response = await fetch("https://api.cometapi.com/kling/v1/videos/image2video", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"image": "https://your-image-host/source.jpg",
"prompt": "A cinematic slow push-in on the subject",
"model_name": "kling-v3",
"mode": "pro",
"duration": "5",
"sound": "off"
}),
});
const result = await response.json();
console.log(result.code, result.data?.task_id);
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.cometapi.com/kling/v1/videos/image2video",
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([
'image' => 'https://your-image-host/source.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/kling/v1/videos/image2video"
payload := strings.NewReader("{\n \"image\": \"https://your-image-host/source.jpg\"\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/kling/v1/videos/image2video")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"image\": \"https://your-image-host/source.jpg\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/kling/v1/videos/image2video")
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 \"image\": \"https://your-image-host/source.jpg\"\n}"
response = http.request(request)
puts response.read_body{
"code": 0,
"message": "success",
"data": {
"task_id": "2032273942220931072",
"task_status": "submitted",
"task_info": {},
"created_at": 1773366840306,
"updated_at": 1773366840306
}
}