Live Try-On 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.
The shopper's device calls three endpoints during a live session: a billing heartbeat, a mid-stream garment
switch and end. They authenticate with the session's clientSecret, never your API key. This page is for
teams building their own client, for example a native app or a different media stack.
The easy path is tryiton-live. connectLiveTryOn makes every
call on this page for you, with the right cadence, retries and page-unload handling. See the
Real-Time Virtual Try-On Quickstart.
The session itself is started by your server. See Start a session for the response these endpoints build on, and Billing for how ticks are charged.
Authenticate with the session secret
Every browser endpoint takes the clientSecret from the start response, in one of two places:
secretin the JSON body, or- the
secretquery parameter, e.g..../end?secret=.... Use this for the page-unload request, which can't send a JSON content type.
When both are present, the body wins. A missing or wrong secret, or an unknown session, answers
404 NotFound ("Session not found."), so the endpoints never reveal whether a session exists. A session id that
isn't 24 hex characters is 400 BadRequest.
The secret only works for that one session's browser endpoints. Don't log or store it.
CORS and rate limits
The browser endpoints accept cross-origin requests from any site and need no cookies. The CORS preflight is cached for 10 minutes. The server endpoints are not CORS-open.
| Endpoint | Limit |
|---|---|
| Heartbeat | 90 requests per minute per IP |
| Switch garment | 30 requests per minute per IP |
| End | 120 requests per minute per IP |
These come on top of the shared 300 requests per minute per IP for every endpoint. Over a limit, the answer is
429 RateLimitExceeded with no Retry-After header. JSON bodies are limited to 10 KB (413 PayloadTooLarge).
Heartbeat
Each heartbeat charges the credit held for the tick that just ended and holds the next one. The server is the source
of truth for the balance: when a heartbeat answers stop: true, stop streaming at once.
POST
https://tryiton.now/api/v1/live/sessions/{sessionId}/heartbeat
curl -X POST https://tryiton.now/api/v1/live/sessions/6b0828e5ed117d43a6d10ad1/heartbeat \
-H "Content-Type: application/json" \
-d '{ "secret": "3f9c2a7b1e4d6f80a2c5e7b9d1f3a5c7e9b2d4f6a8c0e1b3", "connect_ms": 2834 }'| Parameter | Type | Description |
|---|---|---|
secret | string | The session's clientSecret. Required unless sent as ?secret=. |
connect_ms | number | Optional. Milliseconds from the session start to the first try-on frame, for usage records. Rounded and capped at 120000; invalid values are ignored. |
Cadence. Start the billing clock at the first try-on frame, not when the connection opens. Send the first
heartbeat secondsPerCredit seconds after that frame, then one every secondsPerCredit seconds on a fixed schedule
counted from the first frame, so request time doesn't stretch the ticks. This is what tryiton-live does.
- A heartbeat that arrives less than half a tick after the previous charged one, or a retried or concurrent one, is
never charged twice. It answers
stop: falsewith the currentsecondsLeft, so retrying is safe. - If a heartbeat fails, retry after about 2 seconds.
tryiton-liveends the stream after two failures in a row, so it never keeps streaming unbilled. - If heartbeats stop, the session goes
staleafter 3 missed ticks plus 30 seconds (about 36 seconds at the default 2 s per credit) and the held credit is charged, unless no heartbeat was ever charged and no video was reported.
200 OK (keep streaming)
{ "ok": true, "stop": false, "secondsLeft": 18 }200 OK (stop now)
{
"ok": true,
"stop": true,
"reason": "out_of_credits",
"session": {
"id": "6b0828e5ed117d43a6d10ad1",
"status": "ended",
"endReason": "out_of_credits",
"seconds": 24,
"creditsCharged": 12,
"endUserId": "shopper-42",
"createdAt": "2026-11-26T12:21:57.402Z",
"endedAt": "2026-11-26T12:22:24.880Z"
}
}| Field | Description |
|---|---|
stop | false: keep streaming. true: the session has ended; close the stream. You don't need to call end afterwards. |
secondsLeft | With stop: false, seconds the stream may still run: the held credit plus usable credits, capped by max_seconds. |
reason | With stop: true, why the session ended: out_of_credits, time_limit, budget, or the reason it had already ended with (for example user after a server Stop, or superseded). |
session | With stop: true, the final session usage. |
Switch garment
Returns a prepared garment's stream input for a mid-stream switch and records the switch on the session. Hand
garment.input to your media connection: the stream keeps running, with no reconnect. Switching is free.
POST
https://tryiton.now/api/v1/live/sessions/{sessionId}/garments/{garmentId}
curl -X POST https://tryiton.now/api/v1/live/sessions/6b0828e5ed117d43a6d10ad1/garments/6b0827eba2f220ae7dd7c7fb \
-H "Content-Type: application/json" \
-d '{ "secret": "3f9c2a7b1e4d6f80a2c5e7b9d1f3a5c7e9b2d4f6a8c0e1b3" }'garmentId is an id from Prepare a garment, prepared on the
same account as the session. Use the same call to load the first garment when the session was started without
garment_id.
200 OK
{
"ok": true,
"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"
}
}
}| Status | error.name | When |
|---|---|---|
| 400 | BadRequest | The session id or garmentId isn't 24 hex characters. |
| 404 | NotFound | Unknown session, wrong secret, or a garment not prepared on this account. |
| 409 | LiveSessionEnded | The session has already ended, so there's no stream to switch. |
End a session
Ends the session and settles the held credit. It's idempotent: ending an ended session returns it unchanged.
POST
https://tryiton.now/api/v1/live/sessions/{sessionId}/end
curl -X POST https://tryiton.now/api/v1/live/sessions/6b0828e5ed117d43a6d10ad1/end \
-H "Content-Type: application/json" \
-d '{
"secret": "3f9c2a7b1e4d6f80a2c5e7b9d1f3a5c7e9b2d4f6a8c0e1b3",
"reason": "user",
"connected": true,
"connect_ms": 2834
}'| Parameter | Type | Default | Description |
|---|---|---|---|
secret | string | — | The session's clientSecret. Required unless sent as ?secret=. |
reason | string | unload | One of user, idle, hidden, error, unload. Any other value is recorded as unload. |
connected | boolean | — | Whether try-on video ever arrived. Send false only when no try-on frame arrived. |
connect_ms | number | — | Milliseconds from the session start to the first try-on frame. Rounded and capped at 120000. |
error | string | — | What went wrong. Kept only when reason is error, cut to 300 characters. |
The response is { "ok": true, "session": { ... } }, the final session as in
Get a session.
Billing. The held credit is charged (a partial tick rounds up), with two exceptions where it's returned:
connectedisfalse, no heartbeat was charged yet, and the end arrives within 60 seconds of the session start.connectedis left out and the server never saw the session stream (no charged heartbeat, no video reported).
Sending connected: false more than 60 seconds after the start charges the held credit.
Ending when the page closes
A closing page can't wait for a CORS preflight. Send the end as a keepalive request with a text/plain body (a
CORS-simple request) and the secret in the URL:
fetch(`https://tryiton.now/api/v1/live/sessions/${sessionId}/end?secret=${encodeURIComponent(clientSecret)}`, {
method: "POST",
keepalive: true,
headers: { "Content-Type": "text/plain" },
body: JSON.stringify({ reason: "unload", connected: true, connect_ms: 2834 }),
});The text/plain body is parsed as JSON, so reason, connected and connect_ms count exactly as in a JSON
request. A body that isn't a JSON object (empty, malformed, an array) counts as empty: the session ends with
reason: "unload" and the held credit is charged.
Building your own client
- Get the start response from your server. Keep
clientSecretin memory only. - Open the camera and connect to the media provider named in
connection(provider,model,token), sendinggarment.inputas the first garment. Ifgarmentisnull, load one with Switch garment first.tryiton-livewraps the provider's own browser SDK for this. - At the first try-on frame, start the heartbeat schedule. Show
secondsLeftif you like. - Close the stream at once when a heartbeat answers
stop: true. - End with
connectedset truthfully, and send thetext/plainkeepalive end onpagehide.
Related
- Live Virtual Try-On API: the server endpoints, billing and errors.
- Real-Time Virtual Try-On Quickstart: the
tryiton-liveintegration. - Rate Limits & Concurrency: every limit in one place.
Live Try-On
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.
OpenAPI Spec
Download the OpenAPI 3.1 spec of the virtual try-on API to import it into Postman or Insomnia, generate a client, or hand it to an LLM agent.