Try-On Python Quickstart
Minimal Python Example
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