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:
- 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
composer require tryiton/tryitonRequires 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");
}Prefer to poll yourself? Call $client->getStatus($jobId) in a loop instead of
waitForResult.
Try-On Python Quickstart
Run a virtual try-on in Python using the official tryiton SDK: submit a job, wait for completion, and read the output image URLs.
Try-On Ruby Quickstart
Run a virtual try-on in Ruby using the official tryiton SDK: submit a job, wait for completion, and read the output image URLs.