TryItOn
API Reference

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:

  • secret in the JSON body, or
  • the secret query 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.

EndpointLimit
Heartbeat90 requests per minute per IP
Switch garment30 requests per minute per IP
End120 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 }'
ParameterTypeDescription
secretstringThe session's clientSecret. Required unless sent as ?secret=.
connect_msnumberOptional. 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: false with the current secondsLeft, so retrying is safe.
  • If a heartbeat fails, retry after about 2 seconds. tryiton-live ends the stream after two failures in a row, so it never keeps streaming unbilled.
  • If heartbeats stop, the session goes stale after 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"
  }
}
FieldDescription
stopfalse: keep streaming. true: the session has ended; close the stream. You don't need to call end afterwards.
secondsLeftWith stop: false, seconds the stream may still run: the held credit plus usable credits, capped by max_seconds.
reasonWith 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).
sessionWith 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"
    }
  }
}
Statuserror.nameWhen
400BadRequestThe session id or garmentId isn't 24 hex characters.
404NotFoundUnknown session, wrong secret, or a garment not prepared on this account.
409LiveSessionEndedThe 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
         }'
ParameterTypeDefaultDescription
secretstring—The session's clientSecret. Required unless sent as ?secret=.
reasonstringunloadOne of user, idle, hidden, error, unload. Any other value is recorded as unload.
connectedboolean—Whether try-on video ever arrived. Send false only when no try-on frame arrived.
connect_msnumber—Milliseconds from the session start to the first try-on frame. Rounded and capped at 120000.
errorstring—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:

  • connected is false, no heartbeat was charged yet, and the end arrives within 60 seconds of the session start.
  • connected is 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

  1. Get the start response from your server. Keep clientSecret in memory only.
  2. Open the camera and connect to the media provider named in connection (provider, model, token), sending garment.input as the first garment. If garment is null, load one with Switch garment first. tryiton-live wraps the provider's own browser SDK for this.
  3. At the first try-on frame, start the heartbeat schedule. Show secondsLeft if you like.
  4. Close the stream at once when a heartbeat answers stop: true.
  5. End with connected set truthfully, and send the text/plain keepalive end on pagehide.

On this page