Guides
Try-On JavaScript Quickstart
Run a virtual try-on in Node.js using the official tryiton SDK: submit a job, wait for completion, and read the output image URLs.
This quickstart uses the official tryiton
Node.js SDK to:
- Submit a try-on to the
/tryon/clothesendpoint. - Wait for the job to finish (the SDK polls
/status/<id>for you). - Read the output image URLs.
Install
npm install tryitonRequires Node.js 18 or later. See all libraries on the SDKs page.
Minimal example
This example uses URLs for the model and garment images. You can also pass a
base64 data URL (data:image/png;base64,...) for either image.
import { TryItOn, TryItOnError } from "tryiton";
const client = new TryItOn({ apiKey: process.env.TRYITON_API_KEY });
async function run() {
try {
// 1. Submit the try-on
const jobId = await client.tryOnClothes({
modelImage: "https://example.com/model.jpg",
garmentImage: "https://example.com/garment.jpg",
category: "clothing",
subcategory: "tops",
});
console.log("Job started:", jobId);
// 2. Wait for completion (polls status until done)
const output = await client.waitForResult(jobId);
// 3. Read the result image URLs (valid for 72 hours)
console.log("Result:", output[0]);
} catch (err) {
if (err instanceof TryItOnError) {
console.error(`Failed (${err.status} ${err.errorName}): ${err.message}`);
} else {
throw err;
}
}
}
run();Prefer to poll yourself? Call client.getStatus(jobId) in a loop instead of
waitForResult.