A dedicated try-on experience with AI-generated prompts. Products on the left, live camera in the center. Click a product and a vision LLM generates the try-on prompt automatically from the garment image and the person's camera frame. This example uses GPT-4o-mini, but any vision-capable LLM works (Claude, Gemini, etc.). A built-in Decart solution is coming soon.
Unlike the e-commerce example which uses hardcoded prompts, this example shows how to use the /api/enhance-prompt endpoint to generate prompts dynamically - useful when you don't know what garments users will upload.
cd examples/standalone
npm installcp .env.example .env.localOpen .env.local and add both keys:
DECART_API_KEY=sk_your_key_here
OPENAI_API_KEY=sk_your_openai_key_hereNote: This example requires both keys. The Decart key powers the realtime try-on, and the OpenAI key powers the prompt generation.
npm run devOpen http://localhost:3000. Your camera will start automatically. Click any product to try it on - the prompt is generated automatically.
Page loads
→ Camera starts automatically (getUserMedia)
→ Fetch client token from /api/tokens
→ Connect to Decart's lucy-vton-latest model (WebRTC)
→ User sees themselves in the live video feed
→ User clicks a product
→ Capture a frame from the camera
→ Send garment image + person frame to /api/enhance-prompt
→ GPT-4o-mini generates a try-on prompt
→ setImage(garment, prompt) sends the garment to the model
→ AI video stream shows the user wearing the garment
When a product is clicked, it generates a prompt and then applies the garment:
const handleSelectProduct = async (product: Product) => {
const blob = await urlToImageBlob(product.image);
const resized = await resizeImageBlob(blob);
// Generate a prompt from the garment image + person camera frame
const prompt = await enhancePrompt(resized, localVideoRef.current);
// Apply the garment
clientRef.current.setImage(resized, {
prompt: prompt || "Try on this garment",
enhance: false,
});
};The enhancePrompt helper (lib/enhance-prompt.ts) sends the garment image and a camera frame to /api/enhance-prompt, which uses GPT-4o-mini to generate a descriptive prompt like:
"Substitute the grey crewneck sweater with a blue and pink flame print hoodie with a kangaroo pocket and oversized fit"
Edit lib/products.ts. Each product just needs a name, image path, and price - no prompt required:
{
name: "Striped Polo",
image: "/products/striped-polo.jpg",
price: 45,
}Place the garment image in public/products/. Use a clean image of just the garment on a white background for best results.
This example uses Next.js + Tailwind, but the core Decart integration works with any React framework. The key files to port:
app/api/tokens/route.ts- adapt to your backend (Express, Fastify, etc.)app/api/enhance-prompt/route.ts- adapt to your backendhooks/useDecartRealtime.ts- works in any React app as-ishooks/useCamera.ts- works in any React app as-islib/enhance-prompt.ts- works in any React app as-is
| Variable | Required | Purpose |
|---|---|---|
DECART_API_KEY |
Yes | Creates client tokens for realtime connections |
OPENAI_API_KEY |
Yes | Powers /api/enhance-prompt for auto-generating prompts. Can be swapped for any vision-capable LLM. |
