TryItOn
API Reference

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.

LIVE
Real recordings from one live try-on session: the shopper keeps moving while the garment is swapped mid-stream.

How live try-on works

  1. 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.
  2. Start a session per shopper on your server (POST /live/sessions) and send the whole response to the browser.
  3. The browser streams. tryiton-live opens 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.
  4. 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:

CallerCredentialEndpoints
Your serverYour API key (Authorization: Bearer YOUR_API_KEY)Prepare garment, Start session, Get session, Stop session, Config
The shopper's browserThe 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-live starts 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 with out_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: false within 60 seconds of the start, before any heartbeat was charged (tryiton-live does 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.
  • 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 product
import 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 product
package 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 product
require "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 product
curl -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"
         }'
ParameterTypeDefaultDescription
garment_imagestring—Required. A public http(s) URL or a base64 data URL (data:image/<type>;base64,...). A product photo on a plain background works best.
categorystring(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.
subcategorystring—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"
  }
}
FieldDescription
idPass it to Start a session as garment_id, or to the browser's live.switchGarment(id).
category, subcategoryThe category you sent, else what detection saw, else auto.
descriptionA 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 browser
import 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 browser
package 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 browser
require "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 browser
curl -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.

ParameterTypeDefaultDescription
garment_idstring—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_secondsintegermaxSeconds from ConfigCap for this session, from 10 to maxSeconds.
end_user_idstring—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_originstring—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"
    }
  }
}
FieldDescription
sessionThe new session. Same shape as Get a session.
clientSecretSession-scoped secret for the browser's calls. Never log or store it.
connectionThe 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.
secondsPerCreditTick length for this session, fixed at start.
maxSecondsThis session's cap.
secondsLeftSeconds this session can stream now: the lower of the credit balance and maxSeconds.
garmentThe 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"
  }
}
FieldDescription
statusactive or ended.
endReasonWhy it ended (see End reasons), or null while active.
secondsStreamed seconds once the session has ended. While it's running, the billed time in whole ticks.
creditsChargedCredits charged so far.
endUserIdThe 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
}
FieldDescription
enabledWhether live try-on is available right now. When false, starts fail with 503 LiveTryonUnavailable.
secondsPerCreditSeconds of video one credit buys (one tick).
maxSecondsLongest session allowed, and the upper bound of max_seconds.
minCreditsUsable credits needed to start a session (10 seconds' worth).
maxConcurrentSessionsSessions one account can stream at the same time.

End reasons

endReasonMeaning
userEnded by the shopper, or by your server with Stop.
time_limitReached max_seconds.
out_of_creditsThe next tick couldn't be paid.
supersededThe same end_user_id started a new session. The old one is charged if it streamed, free if it never got video.
staleThe 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.
budgetThe service was at capacity. Applies only to accounts that haven't bought credits or a plan.
errorThe stream failed, for example no video arrived in time.
idle, hidden, unloadReported 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.

Statuserror.nameEndpointWhen
400ImageLoadErrorPreparegarment_image is missing, isn't an http(s) URL or data URL, can't be fetched, or can't be read as an image.
400InvalidCategoryPreparecategory / subcategory isn't a valid pair.
400BadRequestStart, Get, StopAn invalid garment_id, max_seconds, end_user_id or allowed_origin, or a session id that isn't 24 hex characters.
403ForbiddenAllMissing, malformed or unknown API key. On Start, also a disabled account.
404ImageLoadErrorPrepareThe garment_image URL answered 404.
404NotFoundStart, Get, StopUnknown garment_id or session on this account.
409LiveSessionActiveStartTwo starts for the same end_user_id raced. Retry once.
413PayloadTooLargePrepare, StartThe JSON body is over 12 MB on Prepare, or over 10 KB on Start. Send large images as a URL.
429LiveTryonBusyStartThe account already streams maxConcurrentSessions sessions.
429OutOfCreditsStartFewer than minCredits usable credits, or the first credit couldn't be held.
429ConcurrencyLimitExceededStart5 or more credits are already held by in-flight try-ons and sessions on the account.
429RateLimitExceededAllToo many requests. There's no Retry-After header: back off and retry after the 60-second window. See Rate Limits & Concurrency.
500InternalServerErrorAllUnexpected server error, or the API key couldn't be checked. Retry after a delay.
503LiveTryonUnavailableStartLive 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:

  1. Parameters (400, or 404 for an unknown garment_id).
  2. Live try-on switched off: 503 LiveTryonUnavailable.
  3. Account disabled: 403 Forbidden.
  4. At capacity, for accounts that haven't bought credits or a plan: 503 LiveTryonUnavailable.
  5. With end_user_id, the shopper's previous session is ended (superseded; charged only if it streamed).
  6. Already maxConcurrentSessions streams: 429 LiveTryonBusy.
  7. Fewer than minCredits usable credits: 429 OutOfCredits.
  8. Holding the first credit: 429 ConcurrencyLimitExceeded or 429 OutOfCredits.
  9. Two racing starts for the same end_user_id: 409 LiveSessionActive.
  10. Media token or first garment failed to load: 503 LiveTryonUnavailable (the hold is returned).

On this page