Kling
从多张图片生成 Kling 图像
使用 CometAPI 的 Kling 多图生图端点,基于主体、场景和风格图片参考生成一张新图像。
POST
/
kling
/
v1
/
images
/
multi-image2image
cURL
curl https://api.cometapi.com/kling/v1/images/multi-image2image \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"model_name": "kling-v2-1",
"prompt": "Two product mascots standing together in a bright studio scene",
"subject_image_list": [
{
"subject_image": "https://your-image-host/subject-1.png"
},
{
"subject_image": "https://your-image-host/subject-2.png"
}
],
"scene_image": "https://your-image-host/scene.png",
"style_image": "https://your-image-host/style.png",
"n": 1,
"aspect_ratio": "1:1"
}'import os
import requests
response = requests.post(
"https://api.cometapi.com/kling/v1/images/multi-image2image",
headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
json={
"model_name": "kling-v2-1",
"prompt": "Two product mascots standing together in a bright studio scene",
"subject_image_list": [
{
"subject_image": "https://your-image-host/subject-1.png"
},
{
"subject_image": "https://your-image-host/subject-2.png"
}
],
"scene_image": "https://your-image-host/scene.png",
"style_image": "https://your-image-host/style.png",
"n": 1,
"aspect_ratio": "1:1"
},
)
result = response.json()
print(result["code"], result.get("data", {}).get("task_id"))
const response = await fetch("https://api.cometapi.com/kling/v1/images/multi-image2image", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"model_name": "kling-v2-1",
"prompt": "Two product mascots standing together in a bright studio scene",
"subject_image_list": [
{
"subject_image": "https://your-image-host/subject-1.png"
},
{
"subject_image": "https://your-image-host/subject-2.png"
}
],
"scene_image": "https://your-image-host/scene.png",
"style_image": "https://your-image-host/style.png",
"n": 1,
"aspect_ratio": "1:1"
}),
});
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/images/multi-image2image",
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([
'subject_image_list' => [
[
'subject_image' => 'https://your-image-host/subject-1.png'
],
[
'subject_image' => 'https://your-image-host/subject-2.png'
]
]
]),
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/images/multi-image2image"
payload := strings.NewReader("{\n \"subject_image_list\": [\n {\n \"subject_image\": \"https://your-image-host/subject-1.png\"\n },\n {\n \"subject_image\": \"https://your-image-host/subject-2.png\"\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/kling/v1/images/multi-image2image")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"subject_image_list\": [\n {\n \"subject_image\": \"https://your-image-host/subject-1.png\"\n },\n {\n \"subject_image\": \"https://your-image-host/subject-2.png\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/kling/v1/images/multi-image2image")
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 \"subject_image_list\": [\n {\n \"subject_image\": \"https://your-image-host/subject-1.png\"\n },\n {\n \"subject_image\": \"https://your-image-host/subject-2.png\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"code": 123,
"message": "<string>",
"data": {
"task_id": "<string>",
"task_status": "submitted",
"created_at": 123,
"updated_at": 123,
"task_status_msg": "<string>",
"task_info": {
"external_task_id": "<string>"
},
"task_result": {}
},
"request_id": "<string>"
}当你希望 Kling 基于多个主体参考图,再结合可选的场景或风格参考图生成一张图像时,请使用此端点。
调用前准备
- 在
subject_image_list中提供 1 到 4 张图片 - 新请求使用
model_name: kling-v2-1 - 仅当核心主体构图已满足需求时,再添加
scene_image或style_image - 将其视为异步生成路由,并保存返回的任务 id
任务流程
1
提交图像生成任务
发送主体图片列表和 prompt,然后保存返回的任务 id。
2
轮询任务
使用对应的 Kling 图像查询路径轮询返回的任务,直到任务进入终态。
3
持久化结果
如果你需要持久访问,请将生成的图像保存到你自己的存储中。
完整参数说明请参阅官方 Kling 文档。
请求体
application/json
最后修改于 2026年6月26日
⌘I
cURL
curl https://api.cometapi.com/kling/v1/images/multi-image2image \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"model_name": "kling-v2-1",
"prompt": "Two product mascots standing together in a bright studio scene",
"subject_image_list": [
{
"subject_image": "https://your-image-host/subject-1.png"
},
{
"subject_image": "https://your-image-host/subject-2.png"
}
],
"scene_image": "https://your-image-host/scene.png",
"style_image": "https://your-image-host/style.png",
"n": 1,
"aspect_ratio": "1:1"
}'import os
import requests
response = requests.post(
"https://api.cometapi.com/kling/v1/images/multi-image2image",
headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
json={
"model_name": "kling-v2-1",
"prompt": "Two product mascots standing together in a bright studio scene",
"subject_image_list": [
{
"subject_image": "https://your-image-host/subject-1.png"
},
{
"subject_image": "https://your-image-host/subject-2.png"
}
],
"scene_image": "https://your-image-host/scene.png",
"style_image": "https://your-image-host/style.png",
"n": 1,
"aspect_ratio": "1:1"
},
)
result = response.json()
print(result["code"], result.get("data", {}).get("task_id"))
const response = await fetch("https://api.cometapi.com/kling/v1/images/multi-image2image", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"model_name": "kling-v2-1",
"prompt": "Two product mascots standing together in a bright studio scene",
"subject_image_list": [
{
"subject_image": "https://your-image-host/subject-1.png"
},
{
"subject_image": "https://your-image-host/subject-2.png"
}
],
"scene_image": "https://your-image-host/scene.png",
"style_image": "https://your-image-host/style.png",
"n": 1,
"aspect_ratio": "1:1"
}),
});
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/images/multi-image2image",
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([
'subject_image_list' => [
[
'subject_image' => 'https://your-image-host/subject-1.png'
],
[
'subject_image' => 'https://your-image-host/subject-2.png'
]
]
]),
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/images/multi-image2image"
payload := strings.NewReader("{\n \"subject_image_list\": [\n {\n \"subject_image\": \"https://your-image-host/subject-1.png\"\n },\n {\n \"subject_image\": \"https://your-image-host/subject-2.png\"\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/kling/v1/images/multi-image2image")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"subject_image_list\": [\n {\n \"subject_image\": \"https://your-image-host/subject-1.png\"\n },\n {\n \"subject_image\": \"https://your-image-host/subject-2.png\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/kling/v1/images/multi-image2image")
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 \"subject_image_list\": [\n {\n \"subject_image\": \"https://your-image-host/subject-1.png\"\n },\n {\n \"subject_image\": \"https://your-image-host/subject-2.png\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"code": 123,
"message": "<string>",
"data": {
"task_id": "<string>",
"task_status": "submitted",
"created_at": 123,
"updated_at": 123,
"task_status_msg": "<string>",
"task_info": {
"external_task_id": "<string>"
},
"task_result": {}
},
"request_id": "<string>"
}