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
| Status | error.name | When | What to do |
|---|---|---|---|
| 400 | BadRequest | Invalid 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. |
| 400 | ImageLoadError | A 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. |
| 400 | InvalidCategory | category/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. |
| 400 | InvalidNumSamples | num_samples isn't an integer from 1 to 4. | Send 1, 2, 3 or 4. |
| 400 | InvalidOutputFormat | output_format isn't png or jpeg. | Send png or jpeg. |
| 400 | InvalidModerationLevel | moderation_level isn't conservative, permissive or none. | Send one of those values or omit it. |
| 400 | InvalidRegion | Tattoo 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. |
| 403 | Forbidden | Missing or malformed Authorization header, unknown API key, or a disabled account. | Check the key and header. See Authentication. Don't retry unchanged. |
| 404 | NotFound | Unknown 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. |
| 404 | ImageLoadError | Starting a live session: the garment image URL returned 404. | Fix the garment URL or prepare the garment again. |
| 409 | LiveSessionActive | A live session is already running for this end_user_id. | Stop the running session, or retry the start. |
| 409 | LiveSessionEnded | A garment switch on a live session that has already ended. | Start a new session. |
| 413 | PayloadTooLarge | The 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. |
| 429 | OutOfCredits | Not 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. |
| 429 | ConcurrencyLimitExceeded | 5 or more credits are already held by running jobs and live sessions. | Wait for running jobs to finish, then retry. See concurrency. |
| 429 | RateLimitExceeded | Over 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. |
| 429 | LiveTryonBusy | The account already has 3 live sessions running. | End a session first, or retry later. |
| 500 | InternalServerError | Something failed on our side, including the API key check or starting the job. | Retry with exponential backoff. Contact support if it persists. |
| 503 | LiveTryonUnavailable | Live 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.
OutOfCreditsis checked beforeConcurrencyLimitExceeded. If both apply, you getOutOfCredits.- 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 withstatus: "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.
| SDK | Error type | Status | Name | Message |
|---|---|---|---|---|
| Node.js | TryItOnError | status (number | null) | errorName | message |
| Python | TryItOnError | status (int | None) | error_name | str(err) |
| Go | *tryiton.Error | Status (int) | Name | Message |
| PHP | TryItOn\TryItOnException | status (?int) | errorName | getMessage() |
| Ruby | Tryiton::Error | status | error_name | message |
Besides the API names above, the SDKs use a few names of their own:
| Name | Status | Meaning |
|---|---|---|
ProcessingError | null (Go: 0) | waitForResult saw status: "failed". The message is the job's failure reason. |
Timeout | null (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. |
NetworkError | null (Go: 0) | The request never got a response: DNS, connection or (outside Node) HTTP timeout. |
ConfigError | null (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
endWhen to retry
| Status | Retry? | How |
|---|---|---|
| 400, 404, 413 | No | The request is wrong. Fix it first. |
| 403 | No | Fix the key or contact support about the account. |
409 LiveSessionActive | After a change | Stop the running session for that end user, then start again. |
429 OutOfCredits | No | Buy credits first. |
429 ConcurrencyLimitExceeded | Yes | Wait until one of your running jobs finishes (poll it), then resubmit. |
429 RateLimitExceeded | Yes | Exponential backoff with jitter, up to the 60-second window. There's no Retry-After header. |
429 LiveTryonBusy | Yes | End one of your live sessions or wait for one to end. |
| 500 | Yes | Exponential backoff, a few attempts. |
| 503 | Yes | Retry later. For live try-on, offer a photo try-on meanwhile. |
Job failed | Yes | Resubmit as a new job. It's free if it fails again. |
SDK Timeout | Don't resubmit yet | Keep polling the same jobId: the job may still complete. |
SDK NetworkError on submit | Check first | The job may have been created. See retries and duplicates. |
A submit that returned an error response created nothing billable, so resubmitting it is safe.
Related
Authentication
Authenticate virtual try-on API requests with a Bearer API key: create a key in the dashboard, call the API from your server, and rotate keys safely.
Credits & Pricing
How virtual try-on API pricing works: 1 credit per output image for clothing, hairstyle and tattoo try-on, per-second live billing, holds and refunds.