Live Virtual Try-On API (Real-Time Webcam)
Real-time virtual try-on API for the shopper's webcam: prepare garments, start live sessions from your server, stream with tryiton-live, billed per second.
The live virtual try-on API shows shoppers themselves wearing a garment in real time, through their webcam. Your
server prepares garments and starts a session with your API key. The shopper's browser streams the video with the
tryiton-live package.
How live try-on works
- Prepare each garment once on your server (
POST /live/garments). This is the slow step, so do it ahead of time, for example when you sync your catalog. - Start a session per shopper on your server (
POST /live/sessions) and send the whole response to the browser. - The browser streams.
tryiton-liveopens the camera and connects to the media provider with the short-lived token from the start response. The video goes from the shopper's device straight to the media provider and never passes through TryItOn's servers. - The browser reports usage. While video flows, it sends billing heartbeats. The session ends when the shopper
or your server ends it, at
max_seconds, or when the balance runs out.
There are two kinds of caller, with two kinds of credential:
| Caller | Credential | Endpoints |
|---|---|---|
| Your server | Your API key (Authorization: Bearer YOUR_API_KEY) | Prepare garment, Start session, Get session, Stop session, Config |
| The shopper's browser | The session's clientSecret (from the start response) | Heartbeat, switch garment, end. tryiton-live makes these calls. See Live Try-On Browser Endpoints |
Keep the API key on your server. The server endpoints are CORS-locked to TryItOn's own sites, so a browser can't call them anyway. The start response carries only credentials scoped to that one session, so it's safe to send to the browser.
Building a storefront? Follow the Real-Time Virtual Try-On Quickstart. It
wires these endpoints to tryiton-live end to end.
Billing
Live try-on uses the same credit balance as photo try-ons. It's billed in ticks: 1 credit buys
secondsPerCredit seconds of video (2 s by default, see Config). Starting needs at least minCredits
usable credits (10 seconds' worth, 5 credits by default).
- At start, 1 credit is held. The hold counts toward the account's concurrency limit like any in-flight try-on.
- Billing begins with the first heartbeat.
tryiton-livestarts the billing clock at the first try-on frame and sends the first heartbeat one tick later. Each heartbeat charges the held credit and holds the next one. When the next credit can't be held, the stream stops without_of_credits. - Ending charges the held credit, so a partial tick rounds up. A stream of 9 seconds at 2 s per credit is charged 5 credits.
- The held credit is returned only if the stream never produced video:
- the browser ends the session with
connected: falsewithin 60 seconds of the start, before any heartbeat was charged (tryiton-livedoes this when the connection fails or no video arrives within 20 seconds), or - the session goes stale before any heartbeat was charged and the browser never reported video.
- the browser ends the session with
- Stopping from your server, or a restart that supersedes a session, charges the held credit only if the session streamed (a charged heartbeat, or video reported). A session that never got video is ended for free.
- Free: preparing garments, switching garments, and a start that returns an error (nothing is held).
secondsLeft in the start and heartbeat responses is how long the session can still stream: the held credit plus
the account's usable credits, capped by max_seconds. See
Pricing & Credits for how the balance works.
Prepare a garment
Turns a product photo into what the live stream needs: the image is fetched, normalized and described, which can
take a few seconds. Results are cached per image and category, so calling it again for the same garment returns the
stored one at once with 200. Preparing is free.
POST
https://tryiton.now/api/v1/live/garments
import { TryItOn } from "tryiton";
const client = new TryItOn({ apiKey: process.env.TRYITON_API_KEY });
const garment = await client.prepareLiveGarment({
garmentImage: "https://example.com/products/shirt.jpg",
category: "clothing",
subcategory: "tops",
});
console.log(garment.id); // store it with the productimport os
from tryiton import TryItOn
client = TryItOn(api_key=os.environ["TRYITON_API_KEY"])
garment = client.prepare_live_garment(
garment_image="https://example.com/products/shirt.jpg",
category="clothing",
subcategory="tops",
)
print(garment["id"]) # store it with the productpackage main
import (
"context"
"fmt"
"log"
"os"
"github.com/tryiton-now/tryiton-go/v2"
)
func main() {
client, err := tryiton.New(os.Getenv("TRYITON_API_KEY"))
if err != nil {
log.Fatal(err)
}
garment, err := client.PrepareLiveGarment(context.Background(), tryiton.PrepareLiveGarmentParams{
GarmentImage: "https://example.com/products/shirt.jpg",
Category: "clothing",
Subcategory: "tops",
})
if err != nil {
log.Fatal(err)
}
fmt.Println(garment.ID) // store it with the product
}<?php
require 'vendor/autoload.php';
use TryItOn\Client;
$client = new Client(getenv('TRYITON_API_KEY'));
$garment = $client->prepareLiveGarment([
'garment_image' => 'https://example.com/products/shirt.jpg',
'category' => 'clothing',
'subcategory' => 'tops',
]);
echo $garment['id'], PHP_EOL; // store it with the productrequire "tryiton"
client = Tryiton::Client.new(api_key: ENV.fetch("TRYITON_API_KEY"))
garment = client.prepare_live_garment(
garment_image: "https://example.com/products/shirt.jpg",
category: "clothing",
subcategory: "tops"
)
puts garment["id"] # store it with the productcurl -X POST https://tryiton.now/api/v1/live/garments \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"garment_image": "https://example.com/products/shirt.jpg",
"category": "clothing",
"subcategory": "tops"
}'| Parameter | Type | Default | Description |
|---|---|---|---|
garment_image | string | — | Required. A public http(s) URL or a base64 data URL (data:image/<type>;base64,...). A product photo on a plain background works best. |
category | string | (detected) | Recommended. What the item is, from the same categories as Clothing & Accessories Try-On, or auto. Detection can misread photos that show more than the item, for example a model wearing the shirt and trousers. |
subcategory | string | — | Required for clothing, jewelry and accessories, e.g. tops for clothing. Must be valid for the category. Don't send one with auto. |
Image limits. A URL is fetched by TryItOn's servers: it must be publicly reachable, at most 25 MB, answer within 15 seconds and take at most 5 redirects. Private and internal addresses are refused. A data URL counts toward the request body, which is limited to 12 MB in total.
201 Created (new) · 200 OK (already prepared)
{
"ok": true,
"garment": {
"id": "6b0827eba2f220ae7dd7c7fb",
"category": "clothing",
"subcategory": "tops",
"description": "a navy short-sleeve pique polo shirt",
"createdAt": "2026-11-26T12:20:59.512Z"
}
}| Field | Description |
|---|---|
id | Pass it to Start a session as garment_id, or to the browser's live.switchGarment(id). |
category, subcategory | The category you sent, else what detection saw, else auto. |
description | A short description of the item from detection, or null. |
Prepared garments are stored on your account (a normalized copy of the image, its category and description) until the account is deleted. See Data Retention & Privacy. Rate limit: 120 requests per minute per account.
Start a session
Starts a live session for one shopper and holds its first credit. Send the whole response to the browser,
unchanged, and pass it to connectLiveTryOn from tryiton-live.
Open the shopper's camera before you call this. A camera permission prompt can take a while, and the session holds a credit from the moment it starts.
POST
https://tryiton.now/api/v1/live/sessions
import { TryItOn } from "tryiton";
const client = new TryItOn({ apiKey: process.env.TRYITON_API_KEY });
const start = await client.startLiveSession({
garmentId: "6b0827eba2f220ae7dd7c7fb",
endUserId: "shopper-42",
allowedOrigin: "https://shop.example.com",
});
console.log(JSON.stringify(start)); // send this whole object to the browserimport json
import os
from tryiton import TryItOn
client = TryItOn(api_key=os.environ["TRYITON_API_KEY"])
start = client.start_live_session(
garment_id="6b0827eba2f220ae7dd7c7fb",
end_user_id="shopper-42",
allowed_origin="https://shop.example.com",
)
print(json.dumps(start)) # send this whole dict to the browserpackage main
import (
"context"
"encoding/json"
"log"
"os"
"github.com/tryiton-now/tryiton-go/v2"
)
func main() {
client, err := tryiton.New(os.Getenv("TRYITON_API_KEY"))
if err != nil {
log.Fatal(err)
}
start, err := client.StartLiveSession(context.Background(), tryiton.StartLiveSessionParams{
GarmentID: "6b0827eba2f220ae7dd7c7fb",
EndUserID: "shopper-42",
AllowedOrigin: "https://shop.example.com",
})
if err != nil {
log.Fatal(err)
}
// Marshals back to the same JSON the API returned: send it to the browser.
json.NewEncoder(os.Stdout).Encode(start)
}<?php
require 'vendor/autoload.php';
use TryItOn\Client;
$client = new Client(getenv('TRYITON_API_KEY'));
$start = $client->startLiveSession([
'garment_id' => '6b0827eba2f220ae7dd7c7fb',
'end_user_id' => 'shopper-42',
'allowed_origin' => 'https://shop.example.com',
]);
echo json_encode($start), PHP_EOL; // send this whole array to the browserrequire "json"
require "tryiton"
client = Tryiton::Client.new(api_key: ENV.fetch("TRYITON_API_KEY"))
start = client.start_live_session(
garment_id: "6b0827eba2f220ae7dd7c7fb",
end_user_id: "shopper-42",
allowed_origin: "https://shop.example.com"
)
puts start.to_json # send this whole hash to the browsercurl -X POST https://tryiton.now/api/v1/live/sessions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"garment_id": "6b0827eba2f220ae7dd7c7fb",
"end_user_id": "shopper-42",
"allowed_origin": "https://shop.example.com"
}'All parameters are optional.
| Parameter | Type | Default | Description |
|---|---|---|---|
garment_id | string | — | A prepared garment to start with. Its stream input comes back in the response, so the first frame doesn't wait on another call. Without it, the browser must name a garment when it connects (connectLiveTryOn(start, { garmentId })). |
max_seconds | integer | maxSeconds from Config | Cap for this session, from 10 to maxSeconds. |
end_user_id | string | — | Your id for the shopper: 1–100 letters, digits and . _ - @ :. With it, each shopper gets one stream: starting again (a reload, a second tab) ends the previous session with endReason: "superseded" (charged only if it streamed). Without it, every start is an independent session. |
allowed_origin | string | — | Your site's origin, e.g. https://shop.example.com (no path). Locks the media token to pages on that origin. Recommended for web integrations; leave it out for native apps. |
201 Created
{
"ok": true,
"session": {
"id": "6b0828e5ed117d43a6d10ad1",
"status": "active",
"endReason": null,
"seconds": 0,
"creditsCharged": 0,
"endUserId": "shopper-42",
"createdAt": "2026-11-26T12:21:57.402Z",
"endedAt": null
},
"clientSecret": "3f9c2a7b1e4d6f80a2c5e7b9d1f3a5c7e9b2d4f6a8c0e1b3",
"connection": { "provider": "decart", "model": "lucy-vton-latest", "token": "ek_live_8f2b9c4d1a7e" },
"secondsPerCredit": 2,
"maxSeconds": 180,
"secondsLeft": 116,
"garment": {
"id": "6b0827eba2f220ae7dd7c7fb",
"category": "clothing",
"subcategory": "tops",
"description": "a navy short-sleeve pique polo shirt",
"createdAt": "2026-11-26T12:20:59.512Z",
"input": {
"prompt": "Substitute the current top with a navy short-sleeve pique polo shirt.",
"enhancePrompt": true,
"referenceImage": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBD"
}
}
}| Field | Description |
|---|---|
session | The new session. Same shape as Get a session. |
clientSecret | Session-scoped secret for the browser's calls. Never log or store it. |
connection | The media provider, model and a short-lived token, capped to this session's length and locked to allowed_origin when given. tryiton-live uses it. |
secondsPerCredit | Tick length for this session, fixed at start. |
maxSeconds | This session's cap. |
secondsLeft | Seconds this session can stream now: the lower of the credit balance and maxSeconds. |
garment | The first garment with its stream input (input), when garment_id was given. Otherwise null. |
Rate limit: 300 starts per hour per account.
Get a session
Status and usage of one of your sessions.
GET
https://tryiton.now/api/v1/live/sessions/{sessionId}
SDKs: getLiveSession(id) (Node.js, PHP), get_live_session(id) (Python, Ruby), GetLiveSession(ctx, id) (Go).
curl https://tryiton.now/api/v1/live/sessions/6b0828e5ed117d43a6d10ad1 \
-H "Authorization: Bearer YOUR_API_KEY"200 OK
{
"ok": true,
"session": {
"id": "6b0828e5ed117d43a6d10ad1",
"status": "ended",
"endReason": "user",
"seconds": 9,
"creditsCharged": 5,
"endUserId": "shopper-42",
"createdAt": "2026-11-26T12:21:57.402Z",
"endedAt": "2026-11-26T12:22:12.118Z"
}
}| Field | Description |
|---|---|
status | active or ended. |
endReason | Why it ended (see End reasons), or null while active. |
seconds | Streamed seconds once the session has ended. While it's running, the billed time in whole ticks. |
creditsCharged | Credits charged so far. |
endUserId | The end_user_id the session was started with, or null. |
Stop a session
Ends a session from your server, for example when the shopper leaves the product page. It ends with
endReason: "user". The held credit is charged if the session streamed and returned if it never got video. It's idempotent: stopping an ended session returns it unchanged.
No request body is needed.
POST
https://tryiton.now/api/v1/live/sessions/{sessionId}/stop
SDKs: stopLiveSession(id) (Node.js, PHP), stop_live_session(id) (Python, Ruby), StopLiveSession(ctx, id) (Go).
The response is the session, as in Get a session.
curl -X POST https://tryiton.now/api/v1/live/sessions/6b0828e5ed117d43a6d10ad1/stop \
-H "Authorization: Bearer YOUR_API_KEY"Config
Live try-on availability and pricing for your account.
GET
https://tryiton.now/api/v1/live/config
SDKs: getLiveConfig() (Node.js, PHP), get_live_config() (Python, Ruby), GetLiveConfig(ctx) (Go).
{
"ok": true,
"enabled": true,
"secondsPerCredit": 2,
"maxSeconds": 180,
"minCredits": 5,
"maxConcurrentSessions": 3
}| Field | Description |
|---|---|
enabled | Whether live try-on is available right now. When false, starts fail with 503 LiveTryonUnavailable. |
secondsPerCredit | Seconds of video one credit buys (one tick). |
maxSeconds | Longest session allowed, and the upper bound of max_seconds. |
minCredits | Usable credits needed to start a session (10 seconds' worth). |
maxConcurrentSessions | Sessions one account can stream at the same time. |
End reasons
endReason | Meaning |
|---|---|
user | Ended by the shopper, or by your server with Stop. |
time_limit | Reached max_seconds. |
out_of_credits | The next tick couldn't be paid. |
superseded | The same end_user_id started a new session. The old one is charged if it streamed, free if it never got video. |
stale | The browser stopped sending heartbeats (closed tab, lost network). A session goes stale after 3 missed ticks plus 30 seconds, about 36 seconds at the default 2 s per credit; stale sessions are swept every minute. |
budget | The service was at capacity. Applies only to accounts that haven't bought credits or a plan. |
error | The stream failed, for example no video arrived in time. |
idle, hidden, unload | Reported by the browser: shopper idle, tab hidden, page closed. |
Errors
Errors use the standard envelope { "ok": false, "error": { "name", "message" } }. Branch on error.name. See
Error Codes & Handling.
| Status | error.name | Endpoint | When |
|---|---|---|---|
| 400 | ImageLoadError | Prepare | garment_image is missing, isn't an http(s) URL or data URL, can't be fetched, or can't be read as an image. |
| 400 | InvalidCategory | Prepare | category / subcategory isn't a valid pair. |
| 400 | BadRequest | Start, Get, Stop | An invalid garment_id, max_seconds, end_user_id or allowed_origin, or a session id that isn't 24 hex characters. |
| 403 | Forbidden | All | Missing, malformed or unknown API key. On Start, also a disabled account. |
| 404 | ImageLoadError | Prepare | The garment_image URL answered 404. |
| 404 | NotFound | Start, Get, Stop | Unknown garment_id or session on this account. |
| 409 | LiveSessionActive | Start | Two starts for the same end_user_id raced. Retry once. |
| 413 | PayloadTooLarge | Prepare, Start | The JSON body is over 12 MB on Prepare, or over 10 KB on Start. Send large images as a URL. |
| 429 | LiveTryonBusy | Start | The account already streams maxConcurrentSessions sessions. |
| 429 | OutOfCredits | Start | Fewer than minCredits usable credits, or the first credit couldn't be held. |
| 429 | ConcurrencyLimitExceeded | Start | 5 or more credits are already held by in-flight try-ons and sessions on the account. |
| 429 | RateLimitExceeded | All | Too many requests. There's no Retry-After header: back off and retry after the 60-second window. See Rate Limits & Concurrency. |
| 500 | InternalServerError | All | Unexpected server error, or the API key couldn't be checked. Retry after a delay. |
| 503 | LiveTryonUnavailable | Start | Live try-on is switched off, at capacity (accounts that haven't bought credits or a plan only), or the media token or first garment couldn't be loaded. Nothing was charged. |
Start checks run in this order, so the first failing one is the error you get:
- Parameters (
400, or404for an unknowngarment_id). - Live try-on switched off:
503 LiveTryonUnavailable. - Account disabled:
403 Forbidden. - At capacity, for accounts that haven't bought credits or a plan:
503 LiveTryonUnavailable. - With
end_user_id, the shopper's previous session is ended (superseded; charged only if it streamed). - Already
maxConcurrentSessionsstreams:429 LiveTryonBusy. - Fewer than
minCreditsusable credits:429 OutOfCredits. - Holding the first credit:
429 ConcurrencyLimitExceededor429 OutOfCredits. - Two racing starts for the same
end_user_id:409 LiveSessionActive. - Media token or first garment failed to load:
503 LiveTryonUnavailable(the hold is returned).
Related
- Real-Time Virtual Try-On Quickstart: server endpoint plus
tryiton-livein the browser, step by step. - Live Try-On Browser Endpoints: heartbeat, garment switch and end, for teams building their own client.
- Virtual Try-On SDKs: install the Node.js, Python, Go, PHP or Ruby SDK.
- Pricing & Credits: how the shared credit balance works.
Credits Balance
Check your virtual try-on API credit balance with GET /credits: subscription, purchased and reserved credits, and how to work out what you can spend.
Live: Browser Endpoints
Heartbeat, garment switch and end: the browser endpoints of the real-time virtual try-on API, authenticated by the session secret, for custom live clients.