Kling Virtual Try-on API Documentation
Virtual Try-on V2 - Request Code
POST https://gateway.pixazo.ai/virtual-tryon/v1/r-vton Content-Type: application/json Cache-Control: no-cache Ocp-Apim-Subscription-Key: YOUR_SUBSCRIPTION_KEY { "category": "upper_body", "garm_img": "https://pub-582b7213209642b9b995c96c95a30381.r2.dev/tshirtShortSleeve.jpg", "human_img": "https://pub-582b7213209642b9b995c96c95a30381.r2.dev/model.png", "crop": true, "seed": 40, "steps": 30, "force_dc": false, "mask_only": false, "garment_des": "cute pink top" } import requests url = "https://gateway.pixazo.ai/virtual-tryon/v1/r-vton" headers = { "Content-Type": "application/json", "Cache-Control": "no-cache", "Ocp-Apim-Subscription-Key": "YOUR_SUBSCRIPTION_KEY" } data = { "category": "upper_body", "garm_img": "https://pub-582b7213209642b9b995c96c95a30381.r2.dev/tshirtShortSleeve.jpg", "human_img": "https://pub-582b7213209642b9b995c96c95a30381.r2.dev/model.png", "crop": True, "seed": 40, "steps": 30, "force_dc": False, "mask_only": False, "garment_des": "cute pink top" } response = requests.post(url, json=data, headers=headers) print(response.json()) const url = 'https://gateway.pixazo.ai/virtual-tryon/v1/r-vton'; const headers = { 'Content-Type': 'application/json', 'Cache-Control': 'no-cache', 'Ocp-Apim-Subscription-Key': 'YOUR_SUBSCRIPTION_KEY' }; const data = { category: 'upper_body', garm_img: 'https://pub-582b7213209642b9b995c96c95a30381.r2.dev/tshirtShortSleeve.jpg', human_img: 'https://pub-582b7213209642b9b995c96c95a30381.r2.dev/model.png', crop: true, seed: 40, steps: 30, force_dc: false, mask_only: false, garment_des: 'cute pink top' }; fetch(url, { method: 'POST', headers: headers, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); curl -v -X POST "https://gateway.pixazo.ai/virtual-tryon/v1/r-vton" -H "Content-Type: application/json" -H "Cache-Control: no-cache" -H "Ocp-Apim-Subscription-Key: YOUR_SUBSCRIPTION_KEY" --data-raw "{ \"category\": \"upper_body\", \"garm_img\": \"https://pub-582b7213209642b9b995c96c95a30381.r2.dev/tshirtShortSleeve.jpg\", \"human_img\": \"https://pub-582b7213209642b9b995c96c95a30381.r2.dev/model.png\", \"crop\": true, \"seed\": 40, \"steps\": 30, \"force_dc\": false, \"mask_only\": false, \"garment_des\": \"cute pink top\" }" import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.time.Duration; public class ApiExample { public static void main(String[] args) throws Exception { HttpClient client = HttpClient.newBuilder() .connectTimeout(Duration.ofSeconds(10)) .build(); String json = """ { "category": "upper_body", "garm_img": "https://pub-582b7213209642b9b995c96c95a30381.r2.dev/tshirtShortSleeve.jpg", "human_img": "https://pub-582b7213209642b9b995c96c95a30381.r2.dev/model.png", "crop": true, "seed": 40, "steps": 30, "force_dc": false, "mask_only": false, "garment_des": "cute pink top" } """; HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://gateway.pixazo.ai/virtual-tryon/v1/r-vton")) .header("Content-Type", "application/json") .header("Cache-Control", "no-cache") .header("Ocp-Apim-Subscription-Key", "YOUR_SUBSCRIPTION_KEY") .POST(HttpRequest.BodyPublishers.ofString(json)) .build(); HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); } } <?php $url = 'https://gateway.pixazo.ai/virtual-tryon/v1/r-vton'; $data = json_encode([ 'category' => 'upper_body', 'garm_img' => 'https://pub-582b7213209642b9b995c96c95a30381.r2.dev/tshirtShortSleeve.jpg', 'human_img' => 'https://pub-582b7213209642b9b995c96c95a30381.r2.dev/model.png', 'crop' => true, 'seed' => 40, 'steps' => 30, 'force_dc' => false, 'mask_only' => false, 'garment_des' => 'cute pink top' ]); $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'Cache-Control: no-cache', 'Ocp-Apim-Subscription-Key: YOUR_SUBSCRIPTION_KEY' ]); $response = curl_exec($ch); curl_close($ch); echo $response; ?> Output
Successful API response:
{ "id": "zdj7tm1g5drj20ckswnsw3jmgc" } Request Body - Virtual Try-on V2
Parameters for /r-vton:
| Parameter | Required | Type | Description |
|---|---|---|---|
| category | Yes | string | Default: "upper_body", Category of garment |
| garm_img | Yes | string | Garment, should match the category, can be a product image or even a photo of someone |
| human_img | Yes | string | Model, if this is not 3:4 check crop |
| crop | Optional | string | Default: false |
| seed | Optional | string | Default: 42, The seed value for random number generation to ensure reproducibility. |
| steps | Optional | string | Default: 30, The number of steps for the transformation process. |
| force_dc | Optional | string | Default: false, Use the DressCode version of IDM-VTON (this is default false, except if category=dresses) |
| mask_only | Optional | string | Default: false, Return only the mask |
| garment_des | Optional | string | Description of garment e.g. Short Sleeve Round Neck T-shirt |
Example Request - Virtual Try-on V2
JSON
{ "category": "upper_body", "garm_img": "https://pub-582b7213209642b9b995c96c95a30381.r2.dev/tshirtShortSleeve.jpg", "human_img": "https://pub-582b7213209642b9b995c96c95a30381.r2.dev/model.png", "crop": true, "seed": 40, "steps": 30, "force_dc": false, "mask_only": false, "garment_des": "cute pink top" } Response - Virtual Try-on V2
JSON
{ "id": "zdj7tm1g5drj20ckswnsw3jmgc" } Request Headers
| Header | Description |
|---|---|
| Content-Type | application/json |
| Cache-Control | no-cache |
| Ocp-Apim-Subscription-Key | Your subscription key for authentication |
Response Handling
The virtual Tryon returns specific HTTP status codes and response bodies to indicate the success or failure of a request. Developers should implement error handling in their applications to manage these responses effectively.
Common Status Codes and Responses
| Status Code | Description | Response Body |
|---|---|---|
| 200 | Success - The request was successfully processed. | { "success": true, ... } |
| 400 | Bad Request - The request contains invalid parameters or missing fields. | { "error": "Invalid request parameters" } |
| 401 | Unauthorized - The provided subscription key is missing or invalid. | { "error": "Invalid or missing authentication" } |
| 403 | Forbidden - The subscription does not have access to this API or action. | { "error": "Access denied for this operation" } |
| 404 | Not Found - The requested resource or endpoint could not be found. | { "error": "Endpoint not found" } |
| 429 | Too Many Requests - The request rate limit has been exceeded. | { "error": "Rate limit exceeded, please retry later" } |
| 500 | Internal Server Error - An unexpected error occurred on the server. | { "error": "An unexpected error occurred, please try again later" } |
Example Error Response
{ "error": "Invalid parameters" } Retrieving Results
After submitting your request, use this endpoint to check status and retrieve results.
Endpoint
POST https://gateway.pixazo.ai/vton-polling/v1/r-vton-get-image
Request Body
{ "id": "zdj7tm1g5drj20ckswnsw3jmgc" } Code Examples
HTTP
POST https://gateway.pixazo.ai/vton-polling/v1/r-vton-get-image Content-Type: application/json Cache-Control: no-cache { "id": "zdj7tm1g5drj20ckswnsw3jmgc" } Python
import requests url = "https://gateway.pixazo.ai/vton-polling/v1/r-vton-get-image" headers = { "Content-Type": "application/json", "Cache-Control": "no-cache" } data = { "id": "zdj7tm1g5drj20ckswnsw3jmgc" } response = requests.post(url, json=data, headers=headers) print(response.json()) JavaScript
const url = 'https://gateway.pixazo.ai/vton-polling/v1/r-vton-get-image'; const headers = { 'Content-Type': 'application/json', 'Cache-Control': 'no-cache' }; const data = { id: 'zdj7tm1g5drj20ckswnsw3jmgc' }; fetch(url, { method: 'POST', headers: headers, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); cURL
curl -v -X POST "https://gateway.pixazo.ai/vton-polling/v1/r-vton-get-image" -H "Content-Type: application/json" -H "Cache-Control: no-cache" --data-raw "{ \"id\": \"zdj7tm1g5drj20ckswnsw3jmgc\" }" Java
import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.time.Duration; public class PollingExample { public static void main(String[] args) throws Exception { HttpClient client = HttpClient.newBuilder() .connectTimeout(Duration.ofSeconds(10)) .build(); String json = """ { "id": "zdj7tm1g5drj20ckswnsw3jmgc" } """; HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://gateway.pixazo.ai/vton-polling/v1/r-vton-get-image")) .header("Content-Type", "application/json") .header("Cache-Control", "no-cache") .POST(HttpRequest.BodyPublishers.ofString(json)) .build(); HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); } } PHP
<?php $url = 'https://gateway.pixazo.ai/vton-polling/v1/r-vton-get-image'; $data = json_encode([ 'id' => 'zdj7tm1g5drj20ckswnsw3jmgc' ]); $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'Cache-Control: no-cache' ]); $response = curl_exec($ch); curl_close($ch); echo $response; ?> Example Success Response
{ "status": "succeeded", "output": "https://example.com/output-image.jpg" } Kling Virtual Try-on API Pricing
| Resolution | Price (USD) |
|---|---|
| All Resolution | $0.14 |