Create a Kling virtual try-on
Use CometAPI Kling Virtual Try-On API to create a try-on image from a person image and clothing image.
curl https://api.cometapi.com/kling/v1/images/kolors-virtual-try-on \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"model_name": "kolors-virtual-try-on-v1",
"human_image": "https://your-image-host/person.jpg",
"cloth_image": "https://your-image-host/garment.jpg"
}'import os
import requests
response = requests.post(
"https://api.cometapi.com/kling/v1/images/kolors-virtual-try-on",
headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
json={
"model_name": "kolors-virtual-try-on-v1",
"human_image": "https://your-image-host/person.jpg",
"cloth_image": "https://your-image-host/garment.jpg"
},
)
result = response.json()
print(result["code"], result.get("data", {}).get("task_id"))
const response = await fetch("https://api.cometapi.com/kling/v1/images/kolors-virtual-try-on", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"model_name": "kolors-virtual-try-on-v1",
"human_image": "https://your-image-host/person.jpg",
"cloth_image": "https://your-image-host/garment.jpg"
}),
});
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/kolors-virtual-try-on",
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([
'human_image' => 'https://your-image-host/person.jpg',
'cloth_image' => 'https://your-image-host/garment.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/images/kolors-virtual-try-on"
payload := strings.NewReader("{\n \"human_image\": \"https://your-image-host/person.jpg\",\n \"cloth_image\": \"https://your-image-host/garment.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/images/kolors-virtual-try-on")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"human_image\": \"https://your-image-host/person.jpg\",\n \"cloth_image\": \"https://your-image-host/garment.jpg\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/kling/v1/images/kolors-virtual-try-on")
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 \"human_image\": \"https://your-image-host/person.jpg\",\n \"cloth_image\": \"https://your-image-host/garment.jpg\"\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>"
}Before you call it
- Provide one
human_imageand onecloth_image - Start with
kolors-virtual-try-on-v1orkolors-virtual-try-on-v1-5 - Use clean clothing product shots or white-background garment images for the first test
Task flow
Submit the try-on task
Poll the task
Persist the result
Authorizations
Bearer token authentication. Use your CometAPI key.
Headers
Must be application/json.
Body
Person image to dress. Image URL or raw Base64 string without a data: prefix. Supported formats: JPG, JPEG, PNG. Maximum 10 MB, minimum 300x300 px, aspect ratio between 1:2.5 and 2.5:1.
Clothing image for the try-on. Image URL or raw Base64 string without a data: prefix. Supported formats: JPG, JPEG, PNG. Maximum 10 MB, minimum 300x300 px, aspect ratio between 1:2.5 and 2.5:1. Supports tops, bottoms, and one-piece dresses.
Virtual try-on model version. Defaults to kolors-virtual-try-on-v1.
kolors-virtual-try-on-v1, kolors-virtual-try-on-v1-5 Webhook URL for task status notifications.
Optional user-defined task ID for your own tracking. Must be unique per account.
Response
Task request accepted or an error response returned by the API.
curl https://api.cometapi.com/kling/v1/images/kolors-virtual-try-on \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"model_name": "kolors-virtual-try-on-v1",
"human_image": "https://your-image-host/person.jpg",
"cloth_image": "https://your-image-host/garment.jpg"
}'import os
import requests
response = requests.post(
"https://api.cometapi.com/kling/v1/images/kolors-virtual-try-on",
headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
json={
"model_name": "kolors-virtual-try-on-v1",
"human_image": "https://your-image-host/person.jpg",
"cloth_image": "https://your-image-host/garment.jpg"
},
)
result = response.json()
print(result["code"], result.get("data", {}).get("task_id"))
const response = await fetch("https://api.cometapi.com/kling/v1/images/kolors-virtual-try-on", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"model_name": "kolors-virtual-try-on-v1",
"human_image": "https://your-image-host/person.jpg",
"cloth_image": "https://your-image-host/garment.jpg"
}),
});
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/kolors-virtual-try-on",
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([
'human_image' => 'https://your-image-host/person.jpg',
'cloth_image' => 'https://your-image-host/garment.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/images/kolors-virtual-try-on"
payload := strings.NewReader("{\n \"human_image\": \"https://your-image-host/person.jpg\",\n \"cloth_image\": \"https://your-image-host/garment.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/images/kolors-virtual-try-on")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"human_image\": \"https://your-image-host/person.jpg\",\n \"cloth_image\": \"https://your-image-host/garment.jpg\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/kling/v1/images/kolors-virtual-try-on")
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 \"human_image\": \"https://your-image-host/person.jpg\",\n \"cloth_image\": \"https://your-image-host/garment.jpg\"\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>"
}