● Developers · SDK 1.x · API v1
Put the fitting room on any product page.
A script tag and two calls in the browser. One endpoint on your backend to report orders, and one more if you want session tokens. Everything here matches the OpenAPI 3.1 spec, which a test keeps in sync with the live routes.
Overview
Two surfaces, two kinds of key.
The widget API (/api/widget) is called from the shopper’s browser by the SDK. It accepts a publishable key from one of your allowed origins, or a short-lived session token your backend minted.
The server API (/api/v1) is called from your backend with a secret key. It mints session tokens, reports orders and manages your catalogue.
| Credential | Where it lives | Sent as |
|---|---|---|
pk_live_… / pk_test_… | Your pages. Works only from an allowed origin. | X-Riti-Key |
rst_… | Your pages, minted per visitor by your backend. 1 to 60 minutes. | Authorization: Bearer |
sk_live_… / sk_test_… | Your servers only. | Authorization: Bearer |
Test keys read and write only test data. Test renders use the real engine, are never billed and have their own daily cap.
Quickstart
Live in four steps.
Load the SDK
Follow
/sdk/v1/for the latest 1.x, or pin an exact build with its integrity hash (see Versioning).Initialise and mount
Pass the product you already render on the page. The try-on button, fitting room and stylist come with it.
Take the cart hand-off
onAddToCart(items)gives you every piece of the look with itseventId. Keep that id on the cart line.Report the order
When the order is placed, your backend posts it to
/api/v1/conversions. Lines carrying a RitieventIdare credited.
<script src="https://api.rititech.app/sdk/v1/riti.js"></script> <div id="riti-tryon"></div> <script> Riti.init({ publishableKey: "pk_test_…", async onAddToCart(items) { // items: [{ productId, variantId, quantity, eventId, lookId?, title? }] await myCart.add(items.map(i => ({ ...i, properties: { riti_event: i.eventId } }))); }, }); Riti.mount("#riti-tryon", { product: { id: "jacket-001", title: "Cropped Linen Jacket", imageUrl: "https://cdn.example.com/jacket.jpg", url: "https://shop.example.com/products/jacket-001", price: 148, variants: [{ id: "v-s", title: "S" }, { id: "v-m", title: "M" }], }, }); Riti.launcher({ label: "Fitting room" }); </script>
SDK reference
The Riti object.
The script tag defines window.Riti. An ES module build (riti.esm.js) with the same API is served from the same path.
Riti.init(options)
Pass at least one of publishableKey and getSessionToken. Throws on an invalid key, emits ready and returns { version, apiUrl }.
| Option | Type | What it does |
|---|---|---|
publishableKey | "pk_live_…" | "pk_test_…" | Sent as X-Riti-Key. Accepted only from a browser on an allowed origin. |
getSessionToken | async () => string | { token, expiresAt } | Session-token auth. See Session tokens. |
onAddToCart(items) | function | Add the items to your cart. Throw or reject to show the shopper an error. |
apiUrl | string | Defaults to the origin the SDK was loaded from plus /api/widget. |
lookUrl(token) | function | Where “View your look” links. Defaults to the hosted look page. |
storeName | string | Names your store in the save-look consent text. |
scope | string | Namespaces the shopper’s fitting room in local storage. Defaults to location.host. |
Riti.mount(target, options)
target is a selector or an element. Mounting the same element twice does nothing.
| Field | Required | Notes |
|---|---|---|
product.id, title, imageUrl | yes | The garment image should show the product clearly on a plain ground. |
product.url | no | Becomes the “Shop this look” link on saved looks and in look.saved. |
product.variants | no | [{ id, title, price?, available? }] for the size picker. |
variantId, price, type, category, tags, brand | no | Used by eligibility rules and the stylist. |
options.button | no | { text, backgroundColor, textColor, radius } |
options.eligibilityMode | no | "all_products" (default) or "automatic" apparel matching. |
Other methods
| Method | What it does |
|---|---|
Riti.mountAll(root?) | Mounts every [data-riti-product] element, whose attribute holds the product as JSON. Returns the count. |
Riti.launcher(options) | A floating “Fitting room” pill with a live count. position, label, offset. Returns { destroy() }. |
Riti.on(name, handler) | Subscribe to an event. A handler that throws is logged and never breaks the widget. |
Riti.off(name, handler?) | Remove one handler, or all handlers for that event. |
Riti.unmount(target) | Removes one widget, its modal and listeners. The element can be mounted again. |
Riti.destroy() | Removes every widget, the launcher and the stylesheet, and forgets the cached session token, so a single-page app can call init() again. |
Riti.use(module) | Registers an optional module up front. Without it, the SDK loads the modules your tenant has on its own, with a pinned integrity hash. |
Events
Listen with Riti.on or the DOM.
Every event is also dispatched on document as a bubbling riti:<name> CustomEvent. The one exception is add-to-cart: riti:add-to-cart fires only when you set no onAddToCart, and then it is the add.
| Event | Detail |
|---|---|
ready | { version, apiUrl }. A handler registered later is still called once. |
tryon:start | { productId, lookId? } |
tryon:success | { eventId, productId, lookId? } |
tryon:error | { error, status, message }. message is what the shopper saw. |
add-to-cart | { items }, each { productId, variantId, quantity, eventId, lookId?, title? } |
look:saved | { id, pageUrl, imageUrl } |
room:open, room:close | none |
room:add | { productId, variantId, source }, where source is product or recommendation |
recommendations:show | { moment, productId, lanes } (Recommendations module) |
recommendations:add | { productId, variantId, lane, moment } (Recommendations module) |
Riti.on("tryon:success", ({ eventId, productId }) => analytics.track("tryon", { eventId, productId })); document.addEventListener("riti:look:saved", (e) => console.log(e.detail.pageUrl));
Session tokens
Keep every key off the page.
A session token is short-lived, can be pinned to one origin, and can carry your own shopper reference. Turn on “require session tokens” in the console and every widget call needs one. Tokens are also the only way to call the widget API where there is no browser Origin, such as a native app. A publishable key alone gets 403 origin_required there.
app.post("/riti-session", async (req, res) => { const r = await fetch("https://api.rititech.app/api/v1/sessions", { method: "POST", headers: { Authorization: `Bearer ${process.env.RITI_SECRET_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify({ origin: "shop.example.com", shopperRef: req.user?.id, ttlSeconds: 900 }), }); res.status(r.status).json(await r.json()); // 201 { token: "rst_…", expiresAt, livemode } });
Riti.init({ getSessionToken: async () => (await fetch("/riti-session", { method: "POST" })).json(), onAddToCart(items) { /* … */ }, });
ttlSecondsruns from 60 to 3600. The default is 900.originmust be one of your allowed hosts, with no wildcards.- The SDK fetches a token lazily, caches it, and fetches a new one 60 seconds before it expires or after a
401 invalid_session_token, retrying the request once. shopperRef(up to 128 characters) is stamped on that shopper’s events, so webhooks and exports join back to your own customer id.
Conversions
Report orders, get attribution.
Send each order from your backend with the secret key. Lines whose eventId belongs to a try-on of your tenant, in the key’s mode, are credited. Reporting the same order again is safe: repeats are idempotent per order and line.
await fetch("https://api.rititech.app/api/v1/conversions", { method: "POST", headers: { Authorization: `Bearer ${process.env.RITI_SECRET_KEY}`, "Content-Type": "application/json" }, body: JSON.stringify({ orderId: "1042", currency: "USD", lineItems: [ { lineItemId: "1042-1", productId: "jacket-001", quantity: 1, unitPrice: 148.00, eventId: "…" }, { lineItemId: "1042-2", productId: "trouser-014", quantity: 1, unitPrice: 128.00, eventId: "…" }, ], }), }); // 202 { "attributed": 2, "ignored": 0 }
orderId, currency (ISO 4217) and 1 to 250 lineItems are required. Each line needs lineItemId, productId, quantity and unitPrice. Lines without a Riti eventId are counted as ignored. A credited order also fires the conversion.attributed webhook.
Webhooks
Signed events to your backend.
Register endpoints in the console, separately for test and live. Every body is an envelope: { id, type, created, livemode, data }.
| Event | Sent when |
|---|---|
tryon.succeeded | A render finished. |
tryon.failed | The render provider failed. |
cart.added | The shopper added a try-on to cart. |
look.saved | The shopper saved a look with their email. Send them pageUrl if consented is true. |
conversion.attributed | An order you reported credited at least one try-on. |
catalog.sync.completed | A catalogue feed synced, with upserted, unchanged, archived and rejected counts. |
catalog.sync.failed | A feed could not be fetched or parsed, or was held because it would have archived too much of the catalogue. |
webhook.test | You pressed “Send test event” in the console. |
Verify the signature
Each request carries Riti-Signature: t=<unix seconds>,v1=<hex>. The hex is HMAC-SHA256 of "<t>.<raw body>", keyed with the endpoint’s signing secret (whsec_…, shown once). Verify against the raw bytes before parsing JSON, and reject timestamps older than five minutes.
const crypto = require("crypto"); function verifyRiti(rawBody, header, secret, toleranceSeconds = 300) { const parts = Object.fromEntries(header.split(",").map((p) => p.split("="))); const t = Number(parts.t); if (!t || Math.abs(Date.now() / 1000 - t) > toleranceSeconds) return false; const expected = crypto.createHmac("sha256", secret).update(`${t}.${rawBody}`).digest(); const given = Buffer.from(parts.v1 || "", "hex"); return given.length === expected.length && crypto.timingSafeEqual(given, expected); }
Delivery
- Respond with any 2xx within 10 seconds.
- Anything else is retried after 1 min, 5 min, 30 min, 2 h, 5 h, 10 h and 24 h, then marked failed. You can redeliver it from the console.
- Delivery is at least once, so deduplicate on the envelope
id. Order is not guaranteed. - Endpoints must be public
httpsURLs. Private, loopback and internal addresses are refused.
Catalog
Give the Recommendations module your products.
Push products with PUT /api/v1/catalog/products (batch upsert), update stock with PATCH /api/v1/catalog/inventory, or register a CSV, TSV or JSON feed that Riti pulls on a schedule. GET /api/v1/catalog/status reports catalogue health for the key’s mode. Archived products stay available to saved looks and are never recommended.
Versioning
Pin the SDK, rely on the contract.
/sdk/v1/riti.js follows the latest 1.x and is cached for five minutes. To pin an exact build, load /sdk/v1.x.y/riti.js with the integrity hash from that version’s manifest.json. Exact builds never change and stay available for the life of the major version.
<script src="https://api.rititech.app/sdk/v1.3.2/riti.js" integrity="sha384-…" crossorigin="anonymous"></script>
- Within a version, changes are additive: new endpoints, new optional fields, new response fields and new webhook types. Ignore fields you do not know, and answer unknown webhook types with a 2xx.
- Breaking changes ship only in a new major (
/api/v2,/sdk/v2). - The previous major keeps working for at least 12 months after the new one is generally available. It answers with
DeprecationandSunsetheaders for that window. - Tenant owners hear about it by email and in the console at the start of the window, then again 90 and 30 days before the sunset date.
API reference
Every public route.
The machine-readable contract is served at /api/openapi.yaml. Base URL: https://api.rititech.app.
Widget API · publishable key or session token
| Method | Path | Purpose |
|---|---|---|
| GET | /api/widget/config | Widget settings for the calling tenant |
| POST | /api/widget/tryon | Render one garment on the shopper’s photo |
| POST | /api/widget/tryon/look | Render a multi-garment outfit |
| POST | /api/widget/looks/plan | Stylist plan for the fitting room (free, not quota-gated) |
| POST | /api/widget/room-add | Count a garment added to the fitting room |
| POST | /api/widget/events/{eventId}/add-to-cart | Mark a try-on as added to cart |
| POST | /api/widget/saved-looks | Save a look and the shopper’s email |
| POST | /api/widget/feedback | Rate a try-on |
| POST | /api/widget/recommendations | Recommendations for a product added to the room |
| POST | /api/widget/recommendations/events | Count recommendation impressions, clicks, room adds and dismissals |
Server API · secret key
| Method | Path | Purpose |
|---|---|---|
| GET | /api/v1/tenant | The calling tenant and its mode |
| POST | /api/v1/sessions | Mint a short-lived browser session token |
| POST | /api/v1/conversions | Report an order for attribution |
| PUT | /api/v1/catalog/products | Create or update catalogue products in a batch |
| GET | /api/v1/catalog/products/{id} | One product, with what Riti derived from it |
| DELETE | /api/v1/catalog/products/{id} | Archive a product |
| PATCH | /api/v1/catalog/inventory | Update stock without resending products |
| GET | /api/v1/catalog/status | Catalogue health for the key’s mode |
| GET | /api/v1/catalog/feeds | Registered catalogue feeds |
| POST | /api/v1/catalog/feeds | Register a CSV, TSV or JSON feed |
| PATCH | /api/v1/catalog/feeds/{id} | Pause, resume or retune a feed |
| DELETE | /api/v1/catalog/feeds/{id} | Remove a feed (its products stay) |
| POST | /api/v1/catalog/feeds/{id}/sync | Sync a feed now |
| GET | /api/v1/catalog/feeds/{id}/runs | The last 20 sync runs of a feed |
Public
| Method | Path | Purpose |
|---|---|---|
| GET | /looks/{token} | Hosted look page |
| GET | /looks/{token}/image | The look image |
| GET | /sdk/{version}/{file} | The browser SDK, its modules and manifest.json |
| GET | /api/openapi.yaml | This contract, machine-readable |
Get test keys and a working demo in one call.
We set up a test tenant, wire it to one of your product pages, and walk your team through the console.