Skip to main content
You need Node.js 22 or later, a JPEG, PNG, or WebP product photo, and a Studio API key with access and credits for image generation. Running this example submits one generation and uses credits.

1. Set your API key

Set this variable in your server environment. Keep it out of source control:

2. Save the example

Save the following as generate.mjs. It uploads your photo, submits to POST /v1/images/generate with an idempotency key, then checks the returned ID until the photo is ready. No npm packages are needed.
generate.mjs

3. Run it with a product photo

The script saves a request file before submission, then prints the accepted job ID and completed result URL. Open the result and compare the garment with your source before using it. The five-minute polling deadline is a client choice, not a completion guarantee. If the image is still processing, resume with its saved ID:
If submission is interrupted before an ID is printed, use the saved request file to retry the same creation safely:
Keep the same API key, workspace, base URL, and request file. The example allows replay within 23 hours of saving the request; older or uncertain submissions need investigation. A request_in_progress response means to retry the same request later or contact support. Do not generate a new key to bypass it. For a specific person instead of a generated model, start with the single-item try-on example.

Reuse a specific avatar or scene

The example describes an adult person in text. For a reusable identity, replace model_text with an avatar ID in asset_ids. Add a preset ID to the same array for a saved visual setup. Use outfit_asset_ids instead of an uploaded image when the product is saved in your wardrobe. Build a reusable asset workflow →