Appy Pie Virtual Try-On API Documentation

Appy Pie’s Virtual Try-On API allows you to overlay garments onto a background image, enabling a seamless virtual fitting experience. This guide provides all the necessary details to integrate, authenticate, and effectively use the API.

Authentication:

To access this API, you must subscribe and acquire a Subscription-Key. Include this key in the request header to authenticate and gain access.

Request Headers:

Content-Type Set to application/json
Cache-Control Recommended to set to no-cache
Ocp-Apim-Subscription-Key YOUR_SUBSCRIPTION_KEY

Endpoint

Base URL: https://gateway.appypie.com/virtual-tryon/v1/r-vton

Request Body

API Parameters: The API POST- https://gateway.appypie.com/virtual-tryon/v1/r-vton takes the following parameters:

Parameters Type Required Description
category string Yes Specifies the category of the garment. Default: "upper_body"
garm_img string Yes The garment image, should match the category, can be a product image or a photo of someone.
human_img string Yes The model image. If not 3:4 ratio, crop the image accordingly.
crop string Optional Determines whether to crop the image. Default: false
seed string Optional A value for random number generation to ensure reproducibility. Default: 42
steps string Optional The number of steps for the transformation process. Default: 30
force_dc string Optional Use the DressCode version of IDM-VTON (if category is 'dresses', default is true). Default: false
mask_only string Optional Return only the mask. Default: false
garment_des string Optional A description of the garment (e.g., Short Sleeve Round Neck T-shirt).

Example Request Body

JSON

{
    "category": "upper_body",
    "garm_img": "https://replicate.delivery/pbxt/KgwTlZyFx5aUU3gc5gMiKuD5nNPTgliMlLUWx160G4z99YjO/sweater.webp",
    "human_img": "https://replicate.delivery/pbxt/KgwTlhCMvDagRrcVzZJbuozNJ8esPqiNAIJS3eMgHrYuHmW4/KakaoTalk_Photo_2024-04-04-21-44-45.png",
    "crop": true,
    "seed": 40,
    "steps": 30,
    "force_dc": false,
    "mask_only": false,
    "garment_des": "cute pink sweatshirt"
}        
    

Request Code

Input
POST https://gateway.appypie.com/virtual-tryon/v1/r-vton HTTP/1.1

Content-Type: application/json
Cache-Control: no-cache

{
    "category": "upper_body",
    "garm_img": "https://replicate.delivery/pbxt/KgwTlZyFx5aUU3gc5gMiKuD5nNPTgliMlLUWx160G4z99YjO/sweater.webp",
    "human_img": "https://replicate.delivery/pbxt/KgwTlhCMvDagRrcVzZJbuozNJ8esPqiNAIJS3eMgHrYuHmW4/KakaoTalk_Photo_2024-04-04-21-44-45.png",
    "crop": true,
    "seed": 40,
    "steps": 30,
    "force_dc": false,
    "mask_only": false,
    "garment_des": "cute pink sweatshirt"
}
import urllib.request, json

try:
    url = "https://gateway.appypie.com/virtual-tryon/v1/r-vton"

    hdr ={
    # Request headers
    'Content-Type': 'application/json',
    'Cache-Control': 'no-cache',
    }

    # Request body
    data =  
    data = json.dumps(data)
    req = urllib.request.Request(url, headers=hdr, data = bytes(data.encode("utf-8")))

    req.get_method = lambda: 'POST'
    response = urllib.request.urlopen(req)
    print(response.getcode())
    print(response.read())
    except Exception as e:
    print(e)
// Request body
const body = {
    "category": "upper_body",
    "garm_img": "https://replicate.delivery/pbxt/KgwTlZyFx5aUU3gc5gMiKuD5nNPTgliMlLUWx160G4z99YjO/sweater.webp",
    "human_img": "https://replicate.delivery/pbxt/KgwTlhCMvDagRrcVzZJbuozNJ8esPqiNAIJS3eMgHrYuHmW4/KakaoTalk_Photo_2024-04-04-21-44-45.png",
    "crop": true,
    "seed": 40,
    "steps": 30,
    "force_dc": false,
    "mask_only": false,
    "garment_des": "cute pink sweatshirt"
};

fetch('https://gateway.appypie.com/virtual-tryon/v1/r-vton', {
        method: 'POST',
        body: JSON.stringify(body),
        // Request headers
        headers: {
            'Content-Type': 'application/json',
            'Cache-Control': 'no-cache',}
    })
    .then(response => {
        console.log(response.status);
        console.log(response.text());
    })
    .catch(err => console.error(err));
curl -v -X POST "https://gateway.appypie.com/virtual-tryon/v1/r-vton" -H "Content-Type: application/json" -H "Cache-Control: no-cache" --data-raw "{
    \"category\": \"upper_body\",
    \"garm_img\": \"https://replicate.delivery/pbxt/KgwTlZyFx5aUU3gc5gMiKuD5nNPTgliMlLUWx160G4z99YjO/sweater.webp\",
    \"human_img\": \"https://replicate.delivery/pbxt/KgwTlhCMvDagRrcVzZJbuozNJ8esPqiNAIJS3eMgHrYuHmW4/KakaoTalk_Photo_2024-04-04-21-44-45.png\",
    \"crop\": true,
    \"seed\": 40,
    \"steps\": 30,
    \"force_dc\": false,
    \"mask_only\": false,
    \"garment_des\": \"cute pink sweatshirt\"
}"
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import java.io.UnsupportedEncodingException;
import java.io.DataInputStream;
import java.io.InputStream;
import java.io.FileInputStream;

public class HelloWorld {

  public static void main(String[] args) {
    try {
        String urlString = "https://gateway.appypie.com/virtual-tryon/v1/r-vton";
        URL url = new URL(urlString);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();

        //Request headers
    connection.setRequestProperty("Content-Type", "application/json");
    
    connection.setRequestProperty("Cache-Control", "no-cache");
    
        connection.setRequestMethod("POST");

        // Request body
        connection.setDoOutput(true);
        connection
            .getOutputStream()
            .write(
             "{ \"category\": \"upper_body\", \"garm_img\": \"https://replicate.delivery/pbxt/KgwTlZyFx5aUU3gc5gMiKuD5nNPTgliMlLUWx160G4z99YjO/sweater.webp\", \"human_img\": \"https://replicate.delivery/pbxt/KgwTlhCMvDagRrcVzZJbuozNJ8esPqiNAIJS3eMgHrYuHmW4/KakaoTalk_Photo_2024-04-04-21-44-45.png\", \"crop\": true, \"seed\": 40, \"steps\": 30, \"force_dc\": false, \"mask_only\": false, \"garment_des\": \"cute pink sweatshirt\" }".getBytes()
             );
    
        int status = connection.getResponseCode();
        System.out.println(status);

        BufferedReader in = new BufferedReader(
            new InputStreamReader(connection.getInputStream())
        );
        String inputLine;
        StringBuffer content = new StringBuffer();
        while ((inputLine = in.readLine()) != null) {
            content.append(inputLine);
        }
        in.close();
        System.out.println(content);

        connection.disconnect();
    } catch (Exception ex) {
      System.out.print("exception:" + ex.getMessage());
    }
  }
}
$url = "https://gateway.appypie.com/virtual-tryon/v1/r-vton";
$curl = curl_init($url);

curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

# Request headers
$headers = array(
    'Content-Type: application/json',
    'Cache-Control: no-cache',);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

# Request body
$request_body = '{
    "category": "upper_body",
    "garm_img": "https://replicate.delivery/pbxt/KgwTlZyFx5aUU3gc5gMiKuD5nNPTgliMlLUWx160G4z99YjO/sweater.webp",
    "human_img": "https://replicate.delivery/pbxt/KgwTlhCMvDagRrcVzZJbuozNJ8esPqiNAIJS3eMgHrYuHmW4/KakaoTalk_Photo_2024-04-04-21-44-45.png",
    "crop": true,
    "seed": 40,
    "steps": 30,
    "force_dc": false,
    "mask_only": false,
    "garment_des": "cute pink sweatshirt"
}';
curl_setopt($curl, CURLOPT_POSTFIELDS, $request_body);

$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);


Response

JSON

HTTP/1.1 200 OK
{
    "id": "8kkgpj5c1nrj00cktgdth9t3v8",
    "urls": {
        "cancel": "https://api.replicate.com/v1/predictions/8kkgpj5c1nrj00cktgdth9t3v8/cancel",
        "get": "https://api.replicate.com/v1/predictions/8kkgpj5c1nrj00cktgdth9t3v8",
        "stream": "https://stream.replicate.com/v1/files/qoxq-n5hhdrbnbtodvm5ri3n6wr56bpvuyhyqgbuclojh5w4bbzslfllq"
    }
}
    

Next Step: Polling for Completion

Polling for Completion

Use the ID received in the initial response to invoke the polling API and check the status of completion.

Request Headers:

Content-Type Set to application/json
Cache-Control Recommended to set to no-cache

Endpoint

Base URL: https://gateway.appypie.com/virtual-tryon-v1/image-to-video-polling

Request Body

API Parameters: The API POST- https://gateway.appypie.com/virtual-tryon-v1/image-to-video-polling takes the following parameters:

Request Body

Pass the id received from the initial response in your request body.

Example Request Body

JSON

{
    "Id": "yry97ajxb1rj20cktdhvjhXXXX"
}          

Request Code

Input
POST https://gateway.appypie.com/vton-polling/v1/r-vton-get-image HTTP/1.1

Content-Type: application/json
Cache-Control: no-cache

{
    "id": "8kkgpj5c1nrj00cktgdth9t3v8"
}
import urllib.request, json

try:
    url = "https://gateway.appypie.com/vton-polling/v1/r-vton-get-image"

    hdr ={
    # Request headers
    'Content-Type': 'application/json',
    'Cache-Control': 'no-cache',
    }

    # Request body
    data =  
    data = json.dumps(data)
    req = urllib.request.Request(url, headers=hdr, data = bytes(data.encode("utf-8")))

    req.get_method = lambda: 'POST'
    response = urllib.request.urlopen(req)
    print(response.getcode())
    print(response.read())
    except Exception as e:
    print(e)
// Request body
const body = {
    "output_location": "917970b6-d7ad-42aa-9749-cfaba998768c",
    "status": "In Progress",
    "output_path": "output_virtual_tryon"
};

fetch('https://gateway.appypie.com/virtual-tryon-v1/image-to-video-polling', {
        method: 'POST',
        body: JSON.stringify(body),
        // Request headers
        headers: {
            'Content-Type': 'application/json',
            'Cache-Control': 'no-cache',}
    })
    .then(response => {
        console.log(response.status);
        console.log(response.text());
    })
    .catch(err => console.error(err));
curl -v -X POST "https://gateway.appypie.com/vton-polling/v1/r-vton-get-image" -H "Content-Type: application/json" -H "Cache-Control: no-cache" --data-raw "{
    \"id\": \"8kkgpj5c1nrj00cktgdth9t3v8\"
}"
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import java.io.UnsupportedEncodingException;
import java.io.DataInputStream;
import java.io.InputStream;
import java.io.FileInputStream;

public class HelloWorld {

  public static void main(String[] args) {
    try {
        String urlString = "https://gateway.appypie.com/vton-polling/v1/r-vton-get-image";
        URL url = new URL(urlString);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();

        //Request headers
    connection.setRequestProperty("Content-Type", "application/json");
    
    connection.setRequestProperty("Cache-Control", "no-cache");
    
        connection.setRequestMethod("POST");

        // Request body
        connection.setDoOutput(true);
        connection
            .getOutputStream()
            .write(
             "{ \"id\": \"8kkgpj5c1nrj00cktgdth9t3v8\" }".getBytes()
             );
    
        int status = connection.getResponseCode();
        System.out.println(status);

        BufferedReader in = new BufferedReader(
            new InputStreamReader(connection.getInputStream())
        );
        String inputLine;
        StringBuffer content = new StringBuffer();
        while ((inputLine = in.readLine()) != null) {
            content.append(inputLine);
        }
        in.close();
        System.out.println(content);

        connection.disconnect();
    } catch (Exception ex) {
      System.out.print("exception:" + ex.getMessage());
    }
  }
}
$url = "https://gateway.appypie.com/vton-polling/v1/r-vton-get-image";
$curl = curl_init($url);

curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

# Request headers
$headers = array(
    'Content-Type: application/json',
    'Cache-Control: no-cache',);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

# Request body
$request_body = '{
    "id": "8kkgpj5c1nrj00cktgdth9t3v8"
}';
curl_setopt($curl, CURLOPT_POSTFIELDS, $request_body);

$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);


Response for Polling

Upon successful polling, the API will return a response indicating the status of the image generation and the final image URL.

Response

JSON

{
    "status": "succeeded",
    "output": "https://replicate.delivery/yhqm/RlCAe6aopRzPcCNapnFyEYnjTp5xmB65O3tTRrpcyOLsB49JA/output.jpg"
}
    

Response Handling

Appy Pie’s Virtual Try-On API returns specific HTTP status codes and response bodies to indicate the success or failure of a request. Developers should implement proper error handling in their applications to manage these responses efficiently.

Common Status Codes and Responses

Status Code Description Response Body
200 Success - The request was successfully processed, and the image generation is in progress or completed. { "msg": "Image Getting Created", ... }
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 prompt parameter"
}
        
    

Conclusion

This documentation provides all the essential information for using Appy Pie’s Virtual Try-On API effectively. Be sure to replace YOUR_SUBSCRIPTION_KEY with the actual key you received when subscribing to the service.