TryItOn
Getting Started

Virtual Try-On API Quickstart

Make your first virtual try-on API call: create an API key, buy credits, install an SDK and run a clothing try-on in Node.js, Python, Go, PHP, Ruby or cURL.

This page takes you from a new account to your first result image. You create an API key, add credits, install an SDK, then submit a clothing try-on and wait for the result.

Make your first virtual try-on API call

Create an API key

  1. Sign in at tryiton.now and open Developer API → API Keys at tryiton.now/app/developer.
  2. Under API Keys (not Site Keys, which are for the storefront widget), click + Create new API Key.
  3. Enter a name (up to 50 characters) and click Create Key.
  4. Copy the key. It is shown only once. Then click I've saved my key.

Store the key in an environment variable. Every sample on this page reads TRYITON_API_KEY:

export TRYITON_API_KEY="YOUR_API_KEY"

Call the API from your server only. The try-on endpoints are CORS-locked to TryItOn's own sites, and anyone who has your key can spend your credits. Never ship the key to a browser or a mobile app. See Authentication & API Keys.

Get credits

Buy a credit pack or a plan at tryiton.now/app/billing. A clothing, hairstyle or tattoo try-on costs 1 credit per output image, and a job that fails is free. One balance covers the API, the TryItOn app, the browser extension, the mobile app and the storefront widget. See Virtual Try-On API Pricing & Credits.

Install an SDK

npm install tryiton

Requires Node.js 18 or later.

pip install tryiton

Requires Python 3.8 or later.

go get github.com/tryiton-now/tryiton-go/v2

Requires Go 1.20 or later.

composer require tryiton/tryiton

Requires PHP 7.4 or later with the curl and json extensions.

gem install tryiton

Requires Ruby 2.6 or later.

Nothing to install. The sample uses curl and sed in a POSIX shell (macOS, Linux, WSL or Git Bash).

Run a clothing try-on and wait for the result

The sample submits a T-shirt try-on, polls the job until it finishes, and prints the result image URL. Replace the two image URLs with public images of your own: a photo of one person, front-facing and well lit, and a product photo of the garment on a plain background. A base64 data URL (data:image/jpeg;base64,...) works too.

tryon.mjs
import { TryItOn } from "tryiton";

const client = new TryItOn({ apiKey: process.env.TRYITON_API_KEY });

const jobId = await client.tryOnFashion({
  modelImage: "https://example.com/model.jpg",
  garmentImage: "https://example.com/tshirt.jpg",
  category: "clothing",
  subcategory: "tops",
});
console.log("Job:", jobId);

const [resultUrl] = await client.waitForResult(jobId, { timeoutMs: 360_000 });
console.log("Result:", resultUrl);

The sample uses import and top-level await, so run it as an ES module: save it as .mjs (node tryon.mjs) or set "type": "module" in your package.json.

tryon.py
import os

from tryiton import TryItOn

client = TryItOn(api_key=os.environ["TRYITON_API_KEY"])

job_id = client.try_on_fashion(
    model_image="https://example.com/model.jpg",
    garment_image="https://example.com/tshirt.jpg",
    category="clothing",
    subcategory="tops",
)
print("Job:", job_id)

urls = client.wait_for_result(job_id, timeout=360)
print("Result:", urls[0])
main.go
package main

import (
	"context"
	"fmt"
	"log"
	"os"
	"time"

	tryiton "github.com/tryiton-now/tryiton-go/v2"
)

func main() {
	client, err := tryiton.New(os.Getenv("TRYITON_API_KEY"))
	if err != nil {
		log.Fatal(err)
	}

	// WaitForResult has no timeout of its own: the context sets it.
	ctx, cancel := context.WithTimeout(context.Background(), 6*time.Minute)
	defer cancel()

	jobID, err := client.TryOnFashion(ctx, tryiton.FashionParams{
		ModelImage:   "https://example.com/model.jpg",
		GarmentImage: "https://example.com/tshirt.jpg",
		Category:     "clothing",
		Subcategory:  "tops",
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Job:", jobID)

	urls, err := client.WaitForResult(ctx, jobID, 2*time.Second)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Result:", urls[0])
}
tryon.php
<?php
require __DIR__ . '/vendor/autoload.php';

use TryItOn\Client;

$client = new Client(getenv('TRYITON_API_KEY'));

$jobId = $client->tryOnFashion([
    'model_image'   => 'https://example.com/model.jpg',
    'garment_image' => 'https://example.com/tshirt.jpg',
    'category'      => 'clothing',
    'subcategory'   => 'tops',
]);
echo "Job: {$jobId}\n";

// Poll every 2 seconds, give up after 360.
$urls = $client->waitForResult($jobId, 2.0, 360.0);
echo "Result: {$urls[0]}\n";
tryon.rb
require "tryiton"

client = Tryiton::Client.new(api_key: ENV["TRYITON_API_KEY"])

job_id = client.try_on_fashion(
  model_image: "https://example.com/model.jpg",
  garment_image: "https://example.com/tshirt.jpg",
  category: "clothing",
  subcategory: "tops"
)
puts "Job: #{job_id}"

urls = client.wait_for_result(job_id, timeout: 360)
puts "Result: #{urls.first}"
tryon.sh
# Submit the job and keep its id.
JOB_ID=$(curl -s https://tryiton.now/api/v1/tryon/fashion \
  -H "Authorization: Bearer $TRYITON_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model_image": "https://example.com/model.jpg",
    "garment_image": "https://example.com/tshirt.jpg",
    "category": "clothing",
    "subcategory": "tops"
  }' | sed -E 's/.*"jobId":"([^"]+)".*/\1/')
echo "Job: $JOB_ID"

# Poll every 2 seconds until the job is no longer processing.
while true; do
  STATUS=$(curl -s "https://tryiton.now/api/v1/status/$JOB_ID" \
    -H "Authorization: Bearer $TRYITON_API_KEY")
  case "$STATUS" in
    *'"status":"processing"'*) sleep 2 ;;
    *) echo "$STATUS"; break ;;
  esac
done

The submit returns 201 with {"ok":true,"jobId":"..."}. The last status response looks like this:

{
  "ok": true,
  "status": "completed",
  "output": ["https://cdn.tryiton.now/USER_ID/tryons/3f2c9a.png"],
  "error": null
}

The samples wait up to 6 minutes, longer than the SDKs' 2-minute default and the 5-minute server-side job timeout, because clothing jobs can take longer under load. If the job fails, the SDKs raise their error class with the name ProcessingError and the job's reason as the message; with cURL you get "status": "failed" and the reason in error. Failed jobs aren't charged.

Save the result

Each URL in output is a PNG (or JPEG with output_format: "jpeg") on TryItOn's CDN. Results are deleted about 72 hours after you submitted the job, so download the images you want to keep.

Next steps

On this page