Below is a minimal Python snippet to demonstrate how to:
  1. POST to the /try-on/run endpoint with your input data.
  2. Poll the status endpoint using the pollingUrl returned from the run request until the generation is completed.
  3. Retrieve the final results from the “output” field.
For detailed documentation (including advanced parameters and usage), please refer to:

Minimal Python Example

This snippet demonstrates a basic request using model and garment image URLs. You can also adapt the code to send local images in Base64 format.
import os
import time
import requests

# 1. Set up the API key and base URL
API_KEY = os.getenv("AYNA_API_KEY")
assert API_KEY, "Please set the AYNA_API_KEY environment variable."
BASE_URL = "https://api.getayna.com/v1"

# 2. POST request to /try-on/run
input_data = {
    "model": "ayna-1.5",
    "input": {
        "model_image": "YOUR_MODEL_IMAGE_URL_OR_BASE64_HERE",
        "garment_image": "YOUR_GARMENT_IMAGE_URL_OR_BASE64_HERE"
    }
}
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {API_KEY}"}
run_response = requests.post(f"{BASE_URL}/try-on/run", json=input_data, headers=headers)
run_data = run_response.json()

# Check if the request was successful
if run_data.get("status") == "failed":
    print("Request failed:", run_data.get("error"))
    exit(1)

polling_url = run_data.get("pollingUrl")
print("Generation started, polling URL:", polling_url)

# 3. Poll the status endpoint using the polling URL
while True:
    status_response = requests.get(polling_url, headers=headers)
    status_data = status_response.json()

    if status_data["status"] == "completed":
        print("Generation completed.")
        # 4. The "output" field contains the final image URL
        print("Result image:", status_data["output"]["image"])
        break

    elif status_data["status"] in ["queued", "processing"]:
        print("Generation status:", status_data["status"])
        time.sleep(3)

    elif status_data["status"] == "failed":
        print("Generation failed:", status_data.get("error"))
        break

    else:
        print("Unknown status:", status_data["status"])
        break