TryOnCloud

Virtual TryOn API Documentation

Complete reference for integrating TryOnCloud virtual TryOn into your applications. New to the platform? Start with the setup tutorial or browse the FAQ.

Getting Started

Authentication

Send your Developer API key in the X-API-KEY header on every request. Create your key in your dashboard → Developer API. Keys start with tk_dev_v1_. Call the API from your server, never the browser.

Header Format:

X-API-KEY: tk_dev_v1_your_key_here
Getting INVALID_KEY? Your full key is shown only once when you create it. A masked value like tk_dev_v1_****ABCD will not work — click Regenerate, copy the full key completely (no spaces), and send that.

Pricing & free trial

Start with 10 free try-ons, then pay as you go from $0.12 per try-on. Credits never expire and there is no monthly reset. When your balance runs out, requests return 402 NO_CREDITS — top up in your dashboard. A failed generation is refunded automatically, so you are never charged for it.

Base URL

https://www.tryoncloud.com/api/v1/generate

API Reference

POST/api/v1/generate

Generate a virtual try-on from two images: a garment and a person (model) photo. One request in, one image out. Send as multipart/form-data or JSON.

Headers

NameValue
X-API-KEYtk_dev_v1_… (required)

Inputs (two images required)

FieldDescription
garment_imageGarment file. Or garment_url (public https image URL) or garment_base64.
person_imagePerson/model file. Or person_base64.

JPEG or PNG, up to 15MB each.

Response (200 OK)

The response body is the finished try-on image (Content-Type: image/png). Read it as raw bytes / a blob — do not JSON-parse it.

Error responses (JSON with error + code)

HTTPcodeMeaning
401NO_KEY / INVALID_KEYMissing or wrong key
400NO_PERSON / NO_GARMENT / BAD_INPUTImage missing or unreadable
402NO_CREDITS / FREE_TRIAL_USEDOut of credits — top up
422CONTENT_FILTEREDBlocked by moderation (refunded)
429RATE_LIMITEDSlow down; honour Retry-After
500GENERATION_FAILEDEngine error (refunded, retry)

Code Examples

cURL (Command Line)

Shell
curl -X POST https://www.tryoncloud.com/api/v1/generate \
  -H "X-API-KEY: tk_dev_v1_your_key_here" \
  -F "garment_image=@garment.jpg" \
  -F "person_image=@model.jpg" \
  --output result.png

Node.js

fetch
// Node 18+ (native fetch & FormData). Call from your server, not the browser.
import fs from "node:fs";

const form = new FormData();
form.append("garment_image", new Blob([fs.readFileSync("garment.jpg")]), "garment.jpg");
form.append("person_image",  new Blob([fs.readFileSync("model.jpg")]),   "model.jpg");

const res = await fetch("https://www.tryoncloud.com/api/v1/generate", {
  method: "POST",
  headers: { "X-API-KEY": "tk_dev_v1_your_key_here" },
  body: form,
});

if (!res.ok) {
  const { error, code } = await res.json();
  throw new Error(`${code}: ${error}`);
}
// The response body IS the PNG — write the bytes to a file.
fs.writeFileSync("result.png", Buffer.from(await res.arrayBuffer()));

Python

requests
import requests

res = requests.post(
    "https://www.tryoncloud.com/api/v1/generate",
    headers={"X-API-KEY": "tk_dev_v1_your_key_here"},
    files={
        "garment_image": open("garment.jpg", "rb"),
        "person_image":  open("model.jpg", "rb"),
    },
    timeout=120,
)

if res.status_code != 200:
    print(res.json())            # {"error": "...", "code": "..."}
    raise SystemExit(1)

with open("result.png", "wb") as f:
    f.write(res.content)          # the response body is the PNG

PHP

cURL
<?php
$ch = curl_init("https://www.tryoncloud.com/api/v1/generate");
curl_setopt_array($ch, [
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_HTTPHEADER => ["X-API-KEY: tk_dev_v1_your_key_here"],
  CURLOPT_POSTFIELDS => [
    "garment_image" => new CURLFile("garment.jpg"),
    "person_image"  => new CURLFile("model.jpg"),
  ],
  CURLOPT_TIMEOUT => 120,
]);
$body   = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($status === 200) {
  file_put_contents("result.png", $body);   // the body IS the PNG
} else {
  echo $body;                                // {"error":"...","code":"..."}
}

Integrate with AI (Cursor, Claude, Codex, Gemini)

Copy this prompt and paste it into your AI coding assistant. It contains the full API contract, so the assistant writes a correct, production-ready integration for your stack in one shot. Replace [MY STACK] with yours (e.g. Next.js API route, Laravel, Django, Express).

You are integrating the TryOnCloud Developer API into my app.

ENDPOINT
  POST https://www.tryoncloud.com/api/v1/generate

AUTH
  Header  X-API-KEY: <my key, starts with tk_dev_v1_>

REQUEST — multipart/form-data OR JSON. Two images required:
  garment_image (file)  OR garment_url (public https URL) OR garment_base64
  person_image  (file)  OR person_base64
  JPEG or PNG, up to 15MB each.

RESPONSE
  200  -> the response BODY IS the finished try-on image (image/png).
          Read it as raw bytes / a blob; do NOT JSON.parse it.
  non-200 -> JSON { "error": string, "code": string }. Codes:
    NO_KEY, INVALID_KEY (401) · NO_PERSON, NO_GARMENT, BAD_INPUT (400)
    NO_CREDITS, FREE_TRIAL_USED (402) · CONTENT_FILTERED (422)
    RATE_LIMITED (429, respect Retry-After) · GENERATION_FAILED (500)

RULES
  - Call this from my server, never the browser; never expose the API key.
  - A failed generation (422/500) refunds the credit automatically; retry once.
  - On 402 stop and tell the user to buy more credits; do not loop.
  - On 429 wait for Retry-After seconds then retry.

Write production code for [MY STACK] that uploads two images, calls this
endpoint, handles every error code above, and saves/returns the resulting PNG.

Best Practices

Secure Your API Keys

  • • Never expose API keys in client-side code
  • • Store keys in environment variables
  • • Rotate keys periodically
  • • Use different keys for dev/production

Handling the Response

  • • On 200, the body is the PNG — read it as bytes/blob
  • • On any error, the body is JSON with error + code
  • • A failed try-on is refunded automatically
  • • Retry once on 500; stop and top up on 402

Image Quality

  • • Use high-resolution images (min 512x512px)
  • • Ensure good lighting and contrast
  • • Avoid heavily compressed images
  • • Test with various product types

Error Handling

  • • Always check response status codes
  • • Handle quota exceeded gracefully
  • • Display user-friendly error messages
  • • Implement retry logic with backoff

Need Help Integrating Virtual TryOn?

Our support team is here to help. View the setup tutorial for a step-by-step walkthrough, or check pricing for your usage tier.