---
title: IDM-VTON AI Model Usage Guide
slug: idm-vton-ai-model-usage-guide
docTags: 
createdAt: 2025-01-07T10:18:29.925Z
---

## Introduction

This document describes how to use the aonweb library to call the IDM-VTON AI model. This model is used for virtual try-on, allowing specified clothing images to be applied to human images.

## Prerequisites

- Node.js environment
- aonweb library installed
- Valid Aonet APPID

## Basic Usage

### 1. Import Required Modules

:::BlockQuote
import \{ AI, AIOptions } from 'aonweb';
:::

### 2. Initialize AI Instance

:::BlockQuote
const ai\_options = new AIOptions(\{
&#x20;   appId: 'your\_app\_id\_here',
&#x20;   dev\_mode: true
});

const aonweb = new AI(ai\_options);
:::

### 3. Prepare Input Data Example

:::BlockQuote
const data = \{
&#x20;   input: \{
&#x20;     "crop": false,
&#x20;     "seed": 42,
&#x20;     "steps": 30,
&#x20;     "category": "upper\_body",
&#x20;     "force\_dc": false,
&#x20;     "garm\_img": "https\://replicate.delivery/pbxt/KgwTlZyFx5aUU3gc5gMiKuD5nNPTgliMlLUWx160G4z99YjO/sweater.webp",
&#x20;     "mask\_img": "https\://replicate.delivery/pbxt/KnaDKqnN0h1DDF5CnK7iRSSkFnJrk9kyRiQlcc5gBcy8gpPA/replicate-prediction-wfj8g6sgmxrgp0cf1gnv7btfh8.jpg",
&#x20;     "human\_img": "https\://replicate.delivery/pbxt/KgwTlhCMvDagRrcVzZJbuozNJ8esPqiNAIJS3eMgHrYuHmW4/KakaoTalk\_Photo\_2024-04-04-21-44-45.png",
&#x20;     "garment\_des": "cute pink top"
&#x20;   }
};
:::

### 4. Call the AI Model

:::BlockQuote
const price = 8; // Cost of the AI call
try \{
&#x20;   const response = await aonweb.prediction("/predictions/ai/idm-vton\@cuuupid", data, price);
&#x20;   // Handle response
&#x20;   console.log("IDM-VTON Response:", response);
} catch (error) \{
&#x20;   // Error handling
&#x20;    console.error("Error generate :", error);
}
:::

### Parameter Description

- seed: Number,Random seed for generating reproducible results
- steps: Number,Provide the steps required for model inference
- garm\_img: String,Garment, should match the category, can be a product image or even a photo of someone
- human\_img: String,Model, if this is not 3:4 check crop
- garment\_des: String,Description of garment e.g. Short Sleeve Round Neck T-shirt
- crop Boolean,Use cropping? (check this if your image is not 3:4)
- category String,Category of garment
- force\_dc Boolean,Use the DressCode version of IDM-VTON (this is default false, except if category=dresses)
- mask\_img String,Mask image, optional (but faster)

### Handling the Response

The model's response will contain the processed results. Depending on your application's needs, you may need to parse and use specific fields from the response.

### Error Handling

Use try-catch blocks to catch and handle possible errors.

## Best Practices

- **Store and Manage API Keys**: Do not hard-code API keys in your code. Use environment variables or secure key management systems.
- **Input Validation**: Validate all input parameters before sending requests.
- **Error Handling**: Implement comprehensive error handling, including network errors, API limits, and invalid responses.
- **Caching Strategy**: Consider implementing caching mechanisms to reduce duplicate requests and improve application performance.
- **Asynchronous Processing**: Use async/await or Promises to handle asynchronous operations, ensuring the main thread is not blocked.

### Notes

- Ensure you have enough API call quota.
- Ensure the validity and accessibility of image URLs.
- Adhere to the API provider's terms of use and restrictions.

## Conclusion

By following this guide, you should be able to successfully integrate and use the IDM-VTON AI model for virtual try-on application development. If you encounter any issues or need further assistance, please refer to the official aonweb documentation or contact technical support.
