TryItOn
Concepts

Error Codes & Handling

Every virtual try-on API error code: HTTP status, error name, cause and fix, plus how each SDK raises errors and which requests are safe to retry.

The virtual try-on API reports errors in two places. A request that can't be accepted gets a non-2xx HTTP response with an error envelope. A job that was accepted but then failed shows up later as status: "failed" on GET /status/{id}, with HTTP 200. Handle both.

The error envelope

Every non-2xx response has the same shape:

{
  "ok": false,
  "error": {
    "name": "OutOfCredits",
    "message": "You do not have enough credits left."
  }
}

Branch on error.name. It's stable and machine-readable. error.message is for humans and logs: its wording can change, so don't match on it.

Error reference

Statuserror.nameWhenWhat to do
400BadRequestInvalid request: the body isn't valid JSON ("Request body is not valid JSON."). On POST /tryon/hairstyle: face_image or haircut is missing, or haircut isn't in the list. On live endpoints: a malformed id, or an invalid max_seconds, end_user_id or allowed_origin.Fix the request. Check the endpoint's parameter table.
400ImageLoadErrorA required image (model_image, garment_image, body_image, design_image) is missing. On POST /live/garments, which loads the image during the request, also an image that is badly formed or can't be fetched.Send a public http(s) URL or a data:image/...;base64, URL. See Image Guidelines.
400InvalidCategorycategory/subcategory isn't a valid pair, or you sent a subcategory with category: "auto".Use a pair from the fashion try-on taxonomy, or omit subcategory.
400InvalidNumSamplesnum_samples isn't an integer from 1 to 4.Send 1, 2, 3 or 4.
400InvalidOutputFormatoutput_format isn't png or jpeg.Send png or jpeg.
400InvalidModerationLevelmoderation_level isn't conservative, permissive or none.Send one of those values or omit it.
400InvalidRegionTattoo region isn't a valid {x, y, w, h} object (or JSON string of one).Send four numbers from 0 to 1, or omit region. See tattoo try-on.
403ForbiddenMissing or malformed Authorization header, unknown API key, or a disabled account.Check the key and header. See Authentication. Don't retry unchanged.
404NotFoundUnknown job id, a job older than 3 days, or an unknown live session or garment. On live browser endpoints, also a wrong device secret.Check the id. Job results can't be fetched after 3 days.
404ImageLoadErrorStarting a live session: the garment image URL returned 404.Fix the garment URL or prepare the garment again.
409LiveSessionActiveA live session is already running for this end_user_id.Stop the running session, or retry the start.
409LiveSessionEndedA garment switch on a live session that has already ended.Start a new session.
413PayloadTooLargeThe JSON body is over 12 MB on /tryon/* and /live/garments, or over 10 KB on any other endpoint.Send large images as a URL instead of base64.
429OutOfCreditsNot enough spendable credits: a photo try-on needs num_samples credits; a live session needs minCredits.Buy credits at tryiton.now/app/billing. Don't retry until you have.
429ConcurrencyLimitExceeded5 or more credits are already held by running jobs and live sessions.Wait for running jobs to finish, then retry. See concurrency.
429RateLimitExceededOver a request rate limit: 300/min per IP on all endpoints, 10/min per account for photo try-ons, or a live limit.Back off and retry after the 60-second window. See Rate Limits.
429LiveTryonBusyThe account already has 3 live sessions running.End a session first, or retry later.
500InternalServerErrorSomething failed on our side, including the API key check or starting the job.Retry with exponential backoff. Contact support if it persists.
503LiveTryonUnavailableLive try-on is turned off for your account (enabled: false in /live/config) or at capacity.Retry later or fall back to a photo try-on.

A few rules that explain the order you see errors in:

  • On photo try-ons the API checks, in order: the API key (403), the per-account rate limit (429), the request body (400), then the account: disabled (403), credits, concurrency.
  • OutOfCredits is checked before ConcurrencyLimitExceeded. If both apply, you get OutOfCredits.
  • The submit request only checks that each required image is present. Fetching and decoding the image happens inside the job, so an unreachable URL or a corrupt file doesn't return 400: the job ends with status: "failed".

Job failures

A failed job is not an HTTP error. GET /status/{id} returns 200 with the reason as a plain string:

{
  "ok": true,
  "status": "failed",
  "output": [],
  "error": "Timed out."
}

error is null unless the job failed. Common causes are an image URL that couldn't be fetched or a job still running after 5 minutes ("Timed out."). A failed job costs nothing. Resubmitting is safe, but fix the input first if the reason points at it. See Jobs, Polling & Retries.

Errors in the SDKs

Every SDK raises one error type for both API errors and job failures. It carries the HTTP status and the API's error.name.

SDKError typeStatusNameMessage
Node.jsTryItOnErrorstatus (number | null)errorNamemessage
PythonTryItOnErrorstatus (int | None)error_namestr(err)
Go*tryiton.ErrorStatus (int)NameMessage
PHPTryItOn\TryItOnExceptionstatus (?int)errorNamegetMessage()
RubyTryiton::Errorstatuserror_namemessage

Besides the API names above, the SDKs use a few names of their own:

NameStatusMeaning
ProcessingErrornull (Go: 0)waitForResult saw status: "failed". The message is the job's failure reason.
Timeoutnull (Go: 0)waitForResult gave up before the job finished. The job may still complete. In Node, a single HTTP request that exceeded timeoutMs also uses this name.
NetworkErrornull (Go: 0)The request never got a response: DNS, connection or (outside Node) HTTP timeout.
ConfigErrornull (Go: 0)The client was created without an API key.
import { TryItOn, TryItOnError } from "tryiton";

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

try {
  const jobId = await client.tryOnFashion({
    modelImage: "https://example.com/model.jpg",
    garmentImage: "https://example.com/shirt.jpg",
  });
  const output = await client.waitForResult(jobId);
  console.log(output);
} catch (err) {
  if (!(err instanceof TryItOnError)) throw err;
  if (err.errorName === "OutOfCredits") {
    console.error("Top up at https://tryiton.now/app/billing");
  } else {
    console.error(err.status, err.errorName, err.message);
  }
}
import os
from tryiton import TryItOn, TryItOnError

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

try:
    job_id = client.try_on_fashion(
        model_image="https://example.com/model.jpg",
        garment_image="https://example.com/shirt.jpg",
    )
    print(client.wait_for_result(job_id))
except TryItOnError as err:
    if err.error_name == "OutOfCredits":
        print("Top up at https://tryiton.now/app/billing")
    else:
        print(err.status, err.error_name, err)
package main

import (
	"context"
	"errors"
	"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)
	}
	ctx := context.Background()

	jobID, err := client.TryOnFashion(ctx, tryiton.FashionParams{
		ModelImage:   "https://example.com/model.jpg",
		GarmentImage: "https://example.com/shirt.jpg",
	})
	if err == nil {
		var output []string
		output, err = client.WaitForResult(ctx, jobID, 2*time.Second)
		if err == nil {
			fmt.Println(output)
			return
		}
	}

	var apiErr *tryiton.Error
	if errors.As(err, &apiErr) && apiErr.Name == "OutOfCredits" {
		log.Fatal("Top up at https://tryiton.now/app/billing")
	}
	log.Fatal(err)
}
<?php
require 'vendor/autoload.php';

use TryItOn\Client;
use TryItOn\TryItOnException;

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

try {
    $jobId = $client->tryOnFashion([
        'model_image' => 'https://example.com/model.jpg',
        'garment_image' => 'https://example.com/shirt.jpg',
    ]);
    print_r($client->waitForResult($jobId));
} catch (TryItOnException $e) {
    if ($e->errorName === 'OutOfCredits') {
        echo "Top up at https://tryiton.now/app/billing\n";
    } else {
        echo "{$e->status} {$e->errorName}: {$e->getMessage()}\n";
    }
}
require "tryiton"

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

begin
  job_id = client.try_on_fashion(
    model_image: "https://example.com/model.jpg",
    garment_image: "https://example.com/shirt.jpg"
  )
  p client.wait_for_result(job_id)
rescue Tryiton::Error => e
  if e.error_name == "OutOfCredits"
    puts "Top up at https://tryiton.now/app/billing"
  else
    puts "#{e.status} #{e.error_name}: #{e.message}"
  end
end

When to retry

StatusRetry?How
400, 404, 413NoThe request is wrong. Fix it first.
403NoFix the key or contact support about the account.
409 LiveSessionActiveAfter a changeStop the running session for that end user, then start again.
429 OutOfCreditsNoBuy credits first.
429 ConcurrencyLimitExceededYesWait until one of your running jobs finishes (poll it), then resubmit.
429 RateLimitExceededYesExponential backoff with jitter, up to the 60-second window. There's no Retry-After header.
429 LiveTryonBusyYesEnd one of your live sessions or wait for one to end.
500YesExponential backoff, a few attempts.
503YesRetry later. For live try-on, offer a photo try-on meanwhile.
Job failedYesResubmit as a new job. It's free if it fails again.
SDK TimeoutDon't resubmit yetKeep polling the same jobId: the job may still complete.
SDK NetworkError on submitCheck firstThe job may have been created. See retries and duplicates.

A submit that returned an error response created nothing billable, so resubmitting it is safe.

On this page