TryItOn
Guides

Try-On PHP Quickstart

Run a virtual try-on in PHP using the official tryiton/tryiton SDK: submit a job, wait for completion, and read the output image URLs.

This quickstart uses the official tryiton/tryiton PHP SDK to:

  1. Submit a try-on to the /tryon/clothes endpoint.
  2. Wait for the job to finish (the SDK polls /status/<id> for you).
  3. Read the output image URLs.

Install

composer require tryiton/tryiton

Requires PHP 7.4 or later with the curl and json extensions. 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.

<?php
require 'vendor/autoload.php';

use TryItOn\Client;
use TryItOn\TryItOnException;

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

try {
    // 1. Submit the try-on
    $jobId = $client->tryOnClothes([
        'model_image'   => 'https://example.com/model.jpg',
        'garment_image' => 'https://example.com/garment.jpg',
        'category'      => 'clothing',
        'subcategory'   => 'tops',
    ]);
    echo "Job started: {$jobId}\n";

    // 2. Wait for completion (polls status until done)
    $urls = $client->waitForResult($jobId);

    // 3. Read the result image URLs (valid for 72 hours)
    echo "Result: {$urls[0]}\n";
} catch (TryItOnException $e) {
    // $e->status (HTTP code) and $e->errorName (e.g. "OutOfCredits") are available
    fwrite(STDERR, "Failed ({$e->status} {$e->errorName}): {$e->getMessage()}\n");
}

The same pattern works for the other models — call $client->tryOnHairstyle(...) or $client->tryOnTattoo(...) instead. See Hairstyle and Tattoo.

Prefer to poll yourself? Call $client->getStatus($jobId) in a loop instead of waitForResult.

On this page