Kling
创建 Kling 数字人视频
使用 CometAPI 中的 Kling Avatar API 从图像生成数字人驱动视频。使用 POST /kling/v1/videos/avatar/image2video 快速创建图生视频数字人。
POST
/
kling
/
v1
/
videos
/
avatar
/
image2video
cURL
curl https://api.cometapi.com/kling/v1/videos/avatar/image2video \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"image": "https://your-image-host/avatar.jpg",
"prompt": "The speaker talks naturally to camera",
"sound_file": "https://your-audio-host/speech.wav",
"mode": "std"
}'import os
import requests
response = requests.post(
"https://api.cometapi.com/kling/v1/videos/avatar/image2video",
headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
json={
"image": "https://your-image-host/avatar.jpg",
"prompt": "The speaker talks naturally to camera",
"sound_file": "https://your-audio-host/speech.wav",
"mode": "std"
},
)
result = response.json()
print(result.get("code"), result.get("data", {}).get("task_id"))
const response = await fetch("https://api.cometapi.com/kling/v1/videos/avatar/image2video", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"image": "https://your-image-host/avatar.jpg",
"prompt": "The speaker talks naturally to camera",
"sound_file": "https://your-audio-host/speech.wav",
"mode": "std"
}),
});
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/avatar/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/avatar.jpg',
'prompt' => 'The speaker talks naturally to camera',
'sound_file' => 'https://your-audio-host/speech.wav'
]),
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/avatar/image2video"
payload := strings.NewReader("{\n \"image\": \"https://your-image-host/avatar.jpg\",\n \"prompt\": \"The speaker talks naturally to camera\",\n \"sound_file\": \"https://your-audio-host/speech.wav\"\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/avatar/image2video")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"image\": \"https://your-image-host/avatar.jpg\",\n \"prompt\": \"The speaker talks naturally to camera\",\n \"sound_file\": \"https://your-audio-host/speech.wav\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/kling/v1/videos/avatar/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/avatar.jpg\",\n \"prompt\": \"The speaker talks naturally to camera\",\n \"sound_file\": \"https://your-audio-host/speech.wav\"\n}"
response = http.request(request)
puts response.read_body{
"code": 123,
"message": "<string>",
"data": {
"task_id": "<string>",
"task_status": "<string>",
"created_at": 123,
"updated_at": 123,
"task_info": {}
}
}使用此端点可通过一张源图像加一个音频源创建会说话的数字人短视频。
调用前准备
- 提供一个数字人
image,可使用公开 URL 或原始 base64 字符串 - 使用符合 Kling 像素要求的数字人图像;过小的缩略图会被生成任务拒绝
- 在
audio_id或sound_file中二选一发送 - 首次请求请尽量保持简单:一张人脸图像、一个音频片段,以及一个可选的简短 prompt
- 当引用的音频属于必须关联的先前任务时,请包含
task_id - 除非你明确需要更高质量路径,否则请先使用
mode: std
音频源规则
- 如果你已经通过 Kling TTS 路径生成了语音,
audio_id是最简单的方式 - 如果你已经有自己的 MP3、WAV、M4A 或 AAC 资源,
sound_file可直接使用 - 文档说明数字人音频时长为 2 到 60 秒
任务流程
1
创建数字人任务
提交图像和一个音频源,然后保存返回的任务 id。
2
轮询任务
继续使用 获取 Kling 任务,直到任务进入终态。
3
保存最终结果
如果你需要在提供商交付 URL 失效后继续保留结果,请将最终资源复制到你自己的存储中。
完整参数说明请参阅 Kling Avatar 官方文档。
请求体
application/json
- Option 1
- Option 2
最后修改于 2026年6月25日
⌘I
cURL
curl https://api.cometapi.com/kling/v1/videos/avatar/image2video \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"image": "https://your-image-host/avatar.jpg",
"prompt": "The speaker talks naturally to camera",
"sound_file": "https://your-audio-host/speech.wav",
"mode": "std"
}'import os
import requests
response = requests.post(
"https://api.cometapi.com/kling/v1/videos/avatar/image2video",
headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
json={
"image": "https://your-image-host/avatar.jpg",
"prompt": "The speaker talks naturally to camera",
"sound_file": "https://your-audio-host/speech.wav",
"mode": "std"
},
)
result = response.json()
print(result.get("code"), result.get("data", {}).get("task_id"))
const response = await fetch("https://api.cometapi.com/kling/v1/videos/avatar/image2video", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"image": "https://your-image-host/avatar.jpg",
"prompt": "The speaker talks naturally to camera",
"sound_file": "https://your-audio-host/speech.wav",
"mode": "std"
}),
});
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/avatar/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/avatar.jpg',
'prompt' => 'The speaker talks naturally to camera',
'sound_file' => 'https://your-audio-host/speech.wav'
]),
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/avatar/image2video"
payload := strings.NewReader("{\n \"image\": \"https://your-image-host/avatar.jpg\",\n \"prompt\": \"The speaker talks naturally to camera\",\n \"sound_file\": \"https://your-audio-host/speech.wav\"\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/avatar/image2video")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"image\": \"https://your-image-host/avatar.jpg\",\n \"prompt\": \"The speaker talks naturally to camera\",\n \"sound_file\": \"https://your-audio-host/speech.wav\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/kling/v1/videos/avatar/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/avatar.jpg\",\n \"prompt\": \"The speaker talks naturally to camera\",\n \"sound_file\": \"https://your-audio-host/speech.wav\"\n}"
response = http.request(request)
puts response.read_body{
"code": 123,
"message": "<string>",
"data": {
"task_id": "<string>",
"task_status": "<string>",
"created_at": 123,
"updated_at": 123,
"task_info": {}
}
}