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 a generate job once, then polls the returned job ID. No npm packages are needed.
generate.mjs

3. Run it with a product photo

The script prints the uploaded image ID, the accepted job ID, and the 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 job is still processing, resume with its saved ID:
If the generation POST times out before you receive an ID, check your recent images in Studio or list images before submitting again. This example intentionally does not retry creation requests automatically.

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 →