Try-On Python Quickstart
Below is a minimal Python snippet to demonstrate how to:
POST to the
/v1/tryon/clothesendpoint with your input data.Poll the
/v1/status/<ID>endpoint until the job is completed.Retrieve the final results from the
"output"field.
Minimal Python Example
This example shows a simple request using URLs for the model and garment images. You can also modify the code to upload local images by converting them to Base64 format.
import os
import time
import requests
# 1. Set up the API key and base URL
API_KEY = os.getenv("TRYITON_API_KEY")
BASE_URL = "https://tryiton.now/api/v1"
# 2. POST request to initialize the try-on
input_data = {
"model_image": "https://example.com/path/to/model.png",
"garment_image": "https://example.com/path/to/garment.png"
}
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {API_KEY}"}
run_response = requests.post(f"{BASE_URL}/tryon/clothes", json=input_data, headers=headers)
run_data = run_response.json()
job_id = run_data.get("id")
print("Job started, ID:", job_id)
# 3. Poll status
while True:
status_response = requests.get(f"{BASE_URL}/status/{job_id}", headers=headers)
status_data = status_response.json()
if status_data["status"] == "completed":
print("Job completed.")
# 4. The "output" field contains the final image URLs
print(status_data["output"])
break
elif status_data["status"] == "processing":
print("Job status:", status_data["status"])
time.sleep(3)
else:
print("Job failed:", status_data.get("error"))
breakLast updated