Vertex AI Virtual Try-On API in Node.js

Savan PadaliyaNovember 19, 202610 min read

The Vertex AI Virtual Try-On API takes a photo of a person and a photo of a garment and returns images of that person wearing it. In Node.js you call it through the @google/genai SDK's ai.models.recontextImage() with the model virtual-try-on-001, or through the REST :predict endpoint. One thing to know before you build on it: Google has deprecated virtual-try-on-001, and its model page lists a platform retirement date of March 15, 2027.

This guide is for Node.js and TypeScript developers adding try-on to a fashion or e-commerce product. It covers setup, working code, every parameter, the limits that bite in production, and how to plan for the retirement. If you have not used Vertex AI before, start with Vertex AI Setup for Node.js Apps.

Naming note: Google now documents Vertex AI's generative features as Gemini Enterprise Agent Platform. The API host is still aiplatform.googleapis.com.

What Is Virtual Try-On on Vertex AI?

Virtual Try-On is an image-to-image model in Vertex AI's Model Garden. You give it two images:

  1. A person image: a photo of a real person or model.
  2. A product image: a clothing item, usually a flat-lay or catalogue photo.

It returns 1 to 4 new images of that person wearing that product, keeping the person's pose, body and background. It is not a text-to-image model: the API does not accept a text prompt for try-on.

SpecValue (from Google's model page)
Model IDvirtual-try-on-001
InputImages only (no text, audio or video)
Max input images per request2 (one person, one product)
Max inline file size7 MB per image
Formatsimage/png, image/jpeg
Output images per request1 to 4
Output sizeSame aspect ratio and resolution as the input
Released / deprecated / retiring2026-01-20 / 2026-09-14 / 2027-03-15

Lifecycle: Should You Still Build on virtual-try-on-001?

Deprecated means the model still works but will be shut down. Google's page lists March 15, 2027 for retirement on the platform. A few third-party trackers show January 2027, so check the official model page before you launch rather than trusting any blog post, including this one.

The practical approach:

  • Building a demo, pilot, or something with a short horizon: virtual-try-on-001 is still the simplest, most purpose-built option. Use it.
  • Building a feature you will run for years: put the model call behind your own interface (shown below) so you can switch to a Gemini image model without touching the rest of your app. Google's virtual try-on capability page already lists Gemini image models (for example gemini-3.1-flash-image and gemini-3-pro-image) alongside virtual-try-on-001.

Prerequisites

  1. A Google Cloud project with billing and the Vertex AI API enabled:
gcloud services enable aiplatform.googleapis.com --project=YOUR_PROJECT_ID
  1. The roles/aiplatform.user role on the identity that makes calls.
  2. Application Default Credentials (gcloud auth application-default login locally, an attached service account in production). If you are deciding between keys and ADC, see Vertex AI API Key vs ADC in Node.js.
  3. Node.js 20+ and the SDK:
npm install @google/genai

Pick a supported region (not global)

Virtual Try-On is regional. Google's model page lists regions including us-central1, us-east1, us-east4, us-west1, europe-west1, europe-west4, asia-northeast1, asia-southeast1 and me-central1. global is not in the list, even though one of Google's own Python samples sets the location to global. Use a listed region close to your users.

Calling Virtual Try-On from Node.js with @google/genai

@google/genai exposes try-on as recontextImage. This method only works on the Vertex AI backend, so the client must use vertexai: true with a project and location.

// try-on.js
import { readFile, writeFile } from 'node:fs/promises';
import { GoogleGenAI } from '@google/genai';

const ai = new GoogleGenAI({
  vertexai: true,
  project: process.env.GOOGLE_CLOUD_PROJECT,
  location: 'us-central1',
});

async function loadImage(path, mimeType) {
  const bytes = await readFile(path);
  return { imageBytes: bytes.toString('base64'), mimeType };
}

const personImage = await loadImage('./person.jpg', 'image/jpeg');
const productImage = await loadImage('./jacket.png', 'image/png');

const response = await ai.models.recontextImage({
  model: 'virtual-try-on-001',
  source: {
    personImage,
    productImages: [{ productImage }],
  },
  config: {
    numberOfImages: 2,
  },
});

for (const [i, generated] of (response.generatedImages ?? []).entries()) {
  if (generated.raiFilteredReason) {
    console.warn(`Image ${i} was filtered: ${generated.raiFilteredReason}`);
    continue;
  }
  const buffer = Buffer.from(generated.image.imageBytes, 'base64');
  await writeFile(`./try-on-${i}.png`, buffer);
}

Two details catch people out:

  • productImages is an array of wrappers, each with a productImage field. Passing raw image objects directly in the array fails.
  • Images can be filtered. A filtered result comes back with raiFilteredReason set instead of image bytes. Always check it, or your code will crash on undefined.

For images already in Cloud Storage, pass { gcsUri: 'gs://bucket/person.jpg', mimeType: 'image/jpeg' } instead of imageBytes. That avoids the 7 MB inline limit and saves a round trip through your server.

TypeScript: A Typed Wrapper You Can Swap Later

The SDK ships its own types, and you should wrap the call in your own function anyway. That function is the single place you change when virtual-try-on-001 retires.

// tryOnService.ts
import { GoogleGenAI, PersonGeneration, type Image } from '@google/genai';

export interface TryOnRequest {
  person: Image;    // { imageBytes, mimeType } or { gcsUri, mimeType }
  garment: Image;
  variants?: 1 | 2 | 3 | 4;
}

export interface TryOnResult {
  images: Buffer[];
  filteredCount: number;
}

const ai = new GoogleGenAI({
  vertexai: true,
  project: process.env.GOOGLE_CLOUD_PROJECT!,
  location: process.env.TRY_ON_REGION ?? 'us-central1',
});

const TRY_ON_MODEL = process.env.TRY_ON_MODEL ?? 'virtual-try-on-001';

export async function tryOn(req: TryOnRequest): Promise<TryOnResult> {
  const res = await ai.models.recontextImage({
    model: TRY_ON_MODEL,
    source: {
      personImage: req.person,
      productImages: [{ productImage: req.garment }],
    },
    config: {
      numberOfImages: req.variants ?? 1,
      personGeneration: PersonGeneration.ALLOW_ADULT,
      outputMimeType: 'image/jpeg',
    },
  });

  const generated = res.generatedImages ?? [];
  const images = generated
    .filter((g) => !g.raiFilteredReason && g.image?.imageBytes)
    .map((g) => Buffer.from(g.image!.imageBytes!, 'base64'));

  return { images, filteredCount: generated.length - images.length };
}

Keeping the model ID in an environment variable means a migration is a config change plus whatever request mapping the new model needs, not a hunt through your codebase. The same typed-boundary pattern is covered in more depth in TypeScript for AI Apps in Node.js.

Every Config Option Explained

SDK option (config)REST parameterWhat it does
numberOfImagessampleCountOutput images per request, 1 to 4. Default 1.
baseStepsbaseStepsDiffusion steps. Higher gives better quality and more latency. Default 32.
seedseedMakes results repeatable. Only works with addWatermark: false.
addWatermarkaddWatermarkAdds Google's watermark to outputs. Default true.
personGenerationpersonGenerationDONT_ALLOW, ALLOW_ADULT (default) or ALLOW_ALL.
safetyFilterLevelsafetySettingBLOCK_LOW_AND_ABOVE, BLOCK_MEDIUM_AND_ABOVE (default), BLOCK_ONLY_HIGH. BLOCK_NONE is restricted.
outputGcsUristorageUriWrites images to Cloud Storage instead of returning bytes.
outputMimeTypeoutputOptions.mimeTypeimage/png or image/jpeg.
outputCompressionQualityoutputOptions.compressionQualityJPEG quality.

My defaults for a storefront: numberOfImages: 2 (let the shopper pick), leave baseSteps at default until you measure latency, keep the watermark on, and write to outputGcsUri when the images go straight to a CDN.

Calling the REST Endpoint Directly

If you cannot use the SDK (an edge runtime, another language, or a queue worker that only does HTTP), the raw request is:

curl -X POST \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Content-Type: application/json" \
  "https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/virtual-try-on-001:predict" \
  -d '{
    "instances": [{
      "personImage": { "image": { "bytesBase64Encoded": "PERSON_BASE64" } },
      "productImages": [{ "image": { "bytesBase64Encoded": "PRODUCT_BASE64" } }]
    }],
    "parameters": { "sampleCount": 1 }
  }'

The response is { "predictions": [{ "mimeType": "image/png", "bytesBase64Encoded": "..." }] }. Note the different field names from the SDK (bytesBase64Encoded instead of imageBytes, sampleCount instead of numberOfImages). The SDK translates between them for you.

Production Considerations

One garment per call. The API reference describes productImages as a single product to try on. For a full outfit, chain calls: put the top on, then use that output as the person image for the trousers. Expect each step to add latency and cost, and cache intermediate results by input hash.

Latency. Image generation takes seconds, not milliseconds. Don't call it inside a synchronous page request. Put it on a background queue, return a job ID, and push the result to the client when it is ready. A simple Redis-backed queue is enough at storefront scale. Do You Need Kafka? A Guide for Startups explains why you rarely need anything heavier.

Input quality decides output quality. Front-facing, full-body or waist-up person photos with plain backgrounds and clear garment edges give the best results. Validate uploads (format, size under 7 MB, minimum resolution) before spending a model call on them.

Consent and privacy. Shopper photos are personal data. Get explicit consent, say how long you keep images, delete them on schedule, and keep the watermark on so generated images are identifiable as AI-made.

Cost. Google bills per generated image. Check the current rate on the Vertex AI pricing page, then multiply by numberOfImages and by the number of chained steps per outfit. Requesting four variants when shoppers look at one quadruples your bill for little gain.

Regional quotas. Quotas are per region. If you hit 429 RESOURCE_EXHAUSTED during a sale, request a quota increase in advance, or spread traffic across two supported regions.

Planning the Migration Off virtual-try-on-001

Because the model is deprecated, build the migration into your plan from day one:

  1. Wrap the call in one service function (the TypeScript example above).
  2. Store inputs (person and garment image references) with each result, so you can re-run a sample set against a new model and compare.
  3. Build a small evaluation set: 30 to 50 person/garment pairs that represent your catalogue (dresses, jackets, patterned shirts), plus a reviewer checklist (garment fidelity, pose preserved, no artefacts on hands and faces).
  4. Test the replacement early. Gemini image models are called with generateContent and a text instruction plus both images, so the request mapping changes. Run your evaluation set months before the retirement date, not weeks.

Frequently Asked Questions

What is the Vertex AI Virtual Try-On API?
It is a Google image model, virtual-try-on-001, that takes a photo of a person and a photo of a clothing product and generates images of that person wearing the product. You call it through the :predict endpoint or the recontextImage method in @google/genai. It returns 1 to 4 PNG or JPEG images per request.

Is virtual-try-on-001 being retired?
Yes. Google's model page lists it as released on January 20, 2026, deprecated on September 14, 2026, and retiring on March 15, 2027 on the platform. Plan a migration path to Gemini image models and check the model page for the current date before launch.

How do I call the Virtual Try-On API from Node.js?
Install @google/genai, create a client with vertexai: true plus your project and a supported region such as us-central1, then call ai.models.recontextImage with model virtual-try-on-001 and a source containing personImage and productImages. The response has generatedImages with base64 image bytes.

What image formats and sizes does Virtual Try-On accept?
PNG and JPEG only, up to 7 MB per image inline, with a maximum of two input images per request: one person and one product. The output keeps the input's aspect ratio and resolution, and you can request 1 to 4 images per call.

Can Virtual Try-On put a full outfit on a person in one call?
Not reliably. The API reference describes productImages as a single product, so plan one garment per request. For a full outfit, chain calls and cache intermediate results.

SP

Savan Padaliya

Technical Partner for Startup Founders. Helps founders build MVPs, scale SaaS products, add AI where it creates leverage, and provides fractional CTO-level leadership.