Dress subjects with a prompt or a garment reference image
import { createDecartClient, models } from "@decartai/sdk";
const model = models.realtime("lucy-vton-3.6");
// Get user's camera stream with model specifications
const stream = await navigator.mediaDevices.getUserMedia({
audio: true,
video: {
frameRate: model.fps,
width: model.width,
height: model.height,
}
});
// Create a client. Never ship your permanent API key to the browser: fetch a short-lived
// client token from your backend instead. The SDK calls this before every connect and reconnect.
const client = createDecartClient({
apiKeyProvider: async () => {
const res = await fetch("/api/realtime-token", { method: "POST" }); // your server: client.tokens.create(...)
const { apiKey } = await res.json();
return apiKey;
}
});
// Connect and try the garment on the live stream
const realtimeClient = await client.realtime.connect(stream, {
model,
// Fast mode (4 credits/sec, 2x standard): lower latency and higher throughput.
// speed: "fast",
mirror: "auto",
onRemoteStream: (transformedStream) => {
const videoElement = document.querySelector("#video-output");
videoElement.srcObject = transformedStream;
}
});
// set() replaces the full state — prompt + garment image atomically
await realtimeClient.set({
prompt: "Wearing a black bomber jacket with a blue logo on the chest",
image: "https://example.com/garment.png",
});
// Switch the garment on the fly
await realtimeClient.set({
prompt: "Wearing a red leather jacket",
image: "https://example.com/red-jacket.png",
});
// Disconnect when done
realtimeClient.disconnect();
promptOptionalDescribe the clothing or accessory to try on.
imageOptionalReference image of the garment or accessory. Passed via initialState.image or realtimeClient.set({ image }).
streamRequiredVideo stream (WebRTC)
speedOptionalFast mode: connect-time option that gives the session lower latency and higher throughput; output quality is unchanged. Billed at 4 credits/sec, 2x standard. Omit for standard mode. (options: fast)
promptstringNoDescribe the clothing or accessory to try on.imageFileNoReference image of the garment or accessory. Passed via initialState.image or realtimeClient.set({ image }).streamFileYesVideo stream (WebRTC)speedstringNoFast mode: connect-time option that gives the session lower latency and higher throughput; output quality is unchanged. Billed at 4 credits/sec, 2x standard. Omit for standard mode. (options: fast)Dress subjects live with a prompt or a garment reference image
Swap outfits, accessories, and garments on a live video stream. Upload a reference image of the garment, describe it with a prompt, or do both — Lucy Virtual Try-On dresses the subject as they move, holding the fit, drape, and body shape stable frame to frame with zero perceptible latency.
Video models are charged per second of generated video. Final cost depends on video duration and selected resolution. Fast mode gives realtime sessions lower latency and higher throughput; output quality is unchanged.