Let shoppers see how clothing looks on them in realtime, using just a webcam. This walkthrough covers the key integration points for adding virtual try-on to an e-commerce product page — from creating secure client tokens to sending garment images with descriptive prompts.Documentation Index
Fetch the complete documentation index at: https://docs.platform.decart.ai/llms.txt
Use this file to discover all available pages before exploring further.
This example uses Next.js, but the same
@decartai/sdk works with any JavaScript framework.What you’ll build
Try-on button
A “Try it on” button on product pages that opens a realtime try-on modal with the user’s webcam.
Instant garment swap
Switch between products without reconnecting — each click sends a new garment image and prompt.
Secure tokens
Your permanent API key stays on the server. The browser only receives a short-lived ephemeral token.
Prerequisites
- Node.js 18+
- A Decart API key from platform.decart.ai
How it works
The entire integration is three steps:- Server creates a short-lived client token from your permanent API key
- Browser opens the camera and establishes a WebRTC connection to
lucy-vton-latest - Browser sends a garment image + descriptive prompt via
set()— the model dresses the person in realtime
Step 1: Create a client token (server-side)
Your backend creates a short-lived token using your permanent API key. The browser never sees your real key.Client tokens have a 10-minute TTL. Create a new token each time a user opens a try-on session. Active WebRTC sessions continue working even after the token expires. See the Client Tokens guide for details.
Step 2: Connect camera to the realtime model
The frontend fetches a token, opens the camera, and establishes a WebRTC connection tolucy-vton-latest.
Step 3: Send a garment image + prompt
Callset() to send a reference garment image with a descriptive prompt. The model applies the garment to the person in realtime.
set() again at any time to switch garments — no need to reconnect.
Product catalog pattern
For e-commerce, pre-write prompts for each product in your catalog. This gives the best results since you can craft specific, detailed descriptions.Prompt patterns
Use the substitute pattern when replacing an existing garment, and the add pattern when adding something new:| Pattern | When to use | Example |
|---|---|---|
| Substitute | Replacing an existing garment | "Substitute the current top with a red plaid flannel shirt with a relaxed fit" |
| Add | Adding something the person isn’t wearing | "Add a wide-brimmed straw hat to the person's head" |
Generating prompts for user uploads
For user-uploaded garment images where you don’t have a pre-written prompt, use any vision LLM to auto-generate one from the garment image:Reference image tips
- Clean garment images work best — just the clothing item, no person wearing it
- White or plain backgrounds are ideal
- At least 512×512 pixels — the model reproduces what it sees, so a clear image produces better results
- If your product images show a model wearing the garment, consider using an image editing model to extract just the clothing item first
More examples
The tryon-examples repo includes six production-ready Next.js examples:| Example | Use case | Highlights |
|---|---|---|
| E-commerce | ”Try it on” on product pages | Pre-written prompts, modal overlay |
| Standalone | Dedicated try-on experience | LLM-generated prompts from garment images |
| Person Detection | Kiosks and unattended displays | Auto-connects only when someone is in frame |
| Full-Featured | Complete try-on experience | Person detection, clothing extraction, extreme precision |
| Digital Mirror | In-store kiosk / smart mirror | Two-device setup (display + phone controller via QR code) |
| Outfit Builder | Multi-garment styling | Compose top + bottom garments into full outfits |
Next steps
Virtual Try-On Guide
Full guide for realtime and batch virtual try-on, including all parameters and SDK examples.
Batch API Reference
Process pre-recorded videos asynchronously with the batch virtual try-on endpoint.
Client Tokens
Secure your integration with short-lived ephemeral tokens.
Streaming Best Practices
Optimize your realtime integration for the best experience.