# Try-On Javascript Quickstart

Below is a minimal JavaScript snippet to demonstrate how to:

1. **POST** to the `/v1/tryon/clothes` endpoint with your input data.
2. **Poll** the `/v1/status/<ID>` endpoint until the job is completed.
3. **Retrieve** the final results from the `"output"` field.

***

#### Minimal JavaScript Example <a href="#minimal-javascript-example" id="minimal-javascript-example"></a>

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.&#x20;

```python
// 1. Set up the API key and base URL
const API_KEY = process.env.TRYITON_API_KEY;
const BASE_URL = "https://tryiton.now/api/v1";
 
// 2. POST request to initialize the try-on
const inputData = {
    model_image: "http://example.com/path/to/model.jpg",
    garment_image: "http://example.com/path/to/garment.jpg"
};
 
const headers = {
    "Content-Type": "application/json",
    "Authorization": `Bearer ${API_KEY}`
};
 
async function runPrediction() {
    try {
        // Make the initial run request
        const runResponse = await fetch(`${BASE_URL}/tryon/clothes`, {
            method: 'POST',
            headers: headers,
            body: JSON.stringify(inputData)
        });
        const runData = await runResponse.json();
        const jobId = runData.id;
        console.log("Job started, ID:", jobId);
 
        // Poll for status
        while (true) {
            const statusResponse = await fetch(`${BASE_URL}/v1/status/${jobId}`, {
                headers: headers
            });
            const statusData = await statusResponse.json();
 
            if (statusData.status === "completed") {
                console.log("Job completed.");
                console.log(statusData.output);
                break;
            } else if (statusData.status === "processing") {
                console.log("Job status:", statusData.status);
                await new Promise(resolve => setTimeout(resolve, 3000));
            } else {
                console.log("Job failed:", statusData.error);
                break;
            }
        }
    } catch (error) {
        console.error("Error:", error.message);
    }
}
 
// Run the prediction
runPrediction();
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tryiton.now/guides/try-on-javascript-quickstart.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
