Full Integration Example
Runnable end-to-end VTON integration flow in Node.js.
This script covers checking service health, checking remaining credits, uploading reference image files, triggering a try-on generation, and logging the output image.
run_vton.ts
import { VTONClient, InsufficientCreditsError } from 'snapit_sdk';
const client = new VTONClient({ apiKey: 'smd_live_your_key_here' });
async function runTryOnWorkflow() {
try {
const developerUserId = 'user_abc123';
// 1. Verify VTON health status
console.log('Checking service health...');
const health = await client.healthCheck();
if (!health.success) {
console.warn('VTON service is currently degraded.');
return;
}
// 2. Audit credits
const balance = await client.getUserCredits(developerUserId);
console.log('Current credit balance:', balance.credits.credits);
// 3. Upload model and clothes images
// Note: Local paths are supported in Node.js environments.
// In browser/serverless, pass File/Blob binary objects instead.
console.log('Uploading reference garments and model photos...');
const uploadRes = await client.uploadImages(developerUserId, [
'./person.jpg',
'./tshirt.png'
], 1000);
const urls = uploadRes.uploaded.map(item => item.url);
console.log('Uploaded assets URLs:', urls);
// 4. Trigger try-on generation
console.log('Generating Try-On rendering...');
const generation = await client.generateTryOn({
model_name: 'quality', // 'fast' (0.25 credits), 'medium' (0.50 credits), or 'quality' (1.00 credits)
inputClothesImageUrls: [urls[1]],
inputPersonImageUrls: [urls[0]],
prompt: 'Put the tshirt on the model',
version: 1.1,
productId: 'sku_9921_blue',
metadata: {
campaign: 'summer_sale_2026'
}
});
if (generation.success) {
console.log('Virtual try-on completed successfully!');
console.log('Output Image URL:', generation.outputImageUrls[0]);
console.log('Transaction Charge:', generation.creditCost, 'credits');
console.log('Generation UUID:', generation.generationId);
}
} catch (error) {
if (error instanceof InsufficientCreditsError) {
console.error('VTON error: Developer credits are insufficient.');
} else {
console.error('VTON error:', error.message);
}
}
}
runTryOnWorkflow();