Kling
Tạo hình ảnh với Kling
Tạo hình ảnh với Kling qua CometAPI: POST /kling/v1/images/generations hỗ trợ tạo hình ảnh từ prompt và tạo hình ảnh bằng ảnh tham chiếu.
POST
/
kling
/
v1
/
images
/
generations
cURL
curl https://api.cometapi.com/kling/v1/images/generations \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"model_name": "kling-v3",
"prompt": "A paper boat floating on calm water at sunrise",
"n": 1,
"aspect_ratio": "1:1"
}'import os
import requests
response = requests.post(
"https://api.cometapi.com/kling/v1/images/generations",
headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
json={
"model_name": "kling-v3",
"prompt": "A paper boat floating on calm water at sunrise",
"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/generations", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"model_name": "kling-v3",
"prompt": "A paper boat floating on calm water at sunrise",
"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/generations",
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([
'prompt' => 'A paper boat floating on calm water at sunrise'
]),
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/generations"
payload := strings.NewReader("{\n \"prompt\": \"A paper boat floating on calm water at sunrise\"\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/generations")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"prompt\": \"A paper boat floating on calm water at sunrise\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/kling/v1/images/generations")
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 \"prompt\": \"A paper boat floating on calm water at sunrise\"\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>"
}Tạo hình ảnh
Để xem tài liệu tham khảo tham số đầy đủ, hãy xem tài liệu Kling chính thức.
Yêu cầu đầu tiên
Bắt đầu vớimodel_name: kling-v3, prompt, n và aspect_ratio. Chỉ thêm ảnh tham chiếu, các thiết lập độ trung thực hoặc các trường nâng cao sau khi yêu cầu đầu tiên trả về một tác vụ có thể sử dụng được. Nếu bỏ qua model_name, hệ thống sẽ dùng một giá trị mặc định tương thích cũ, vì vậy hãy gửi rõ ràng kling-v3 cho các tích hợp mới.
Đọc phản hồi
Lưutask_id được trả về, sau đó poll route truy vấn hình ảnh Kling tương ứng cho đến khi task_status đạt trạng thái kết thúc. Nếu quy trình của bạn cần lưu trữ bền vững, hãy sao chép asset cuối cùng vào lớp lưu trữ của riêng bạn sau khi quá trình tạo hoàn tất.Nội dung
application/json
Phản hồi
200 - application/json
Task request accepted or an error response returned by the API.
Lần sửa đổi cuối 26 tháng 6, 2026
⌘I
cURL
curl https://api.cometapi.com/kling/v1/images/generations \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"model_name": "kling-v3",
"prompt": "A paper boat floating on calm water at sunrise",
"n": 1,
"aspect_ratio": "1:1"
}'import os
import requests
response = requests.post(
"https://api.cometapi.com/kling/v1/images/generations",
headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
json={
"model_name": "kling-v3",
"prompt": "A paper boat floating on calm water at sunrise",
"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/generations", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"model_name": "kling-v3",
"prompt": "A paper boat floating on calm water at sunrise",
"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/generations",
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([
'prompt' => 'A paper boat floating on calm water at sunrise'
]),
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/generations"
payload := strings.NewReader("{\n \"prompt\": \"A paper boat floating on calm water at sunrise\"\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/generations")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"prompt\": \"A paper boat floating on calm water at sunrise\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/kling/v1/images/generations")
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 \"prompt\": \"A paper boat floating on calm water at sunrise\"\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>"
}