TypeScript SDK
Use the SuperStyle API from TypeScript with full type safety.
Type definitions
Section titled “Type definitions”// Request typesinterface IdentifyClothingRequest { image_url: string;}
interface GenerateImageRequest { selfie_base64: string; clothing_description: string; clothing_image_url?: string; mode: "studio" | "environment";}
interface StyleMeRequest { selfie_base64: string; style_preferences?: string; occasion?: string; num_outfits?: number;}
// Response typesinterface ProductLink { title: string; url: string; thumbnail?: string; price?: string; store?: string; snippet?: string;}
interface ClothingItem { item: string; description: string; color: string; style_tags: string[]; category: string; price_range?: string; products: ProductLink[];}
interface IdentifyClothingResponse { items: ClothingItem[];}
interface GenerateImageResponse { image_base64: string; mime_type: string;}
interface OutfitSuggestion { description: string; items: string[]; style: string; image_base64: string; mime_type: string;}
interface StyleMeResponse { outfits: OutfitSuggestion[];}
interface UsageResponse { total_requests: number; requests_by_endpoint: Record<string, number>; requests_today: number; recent_requests: { endpoint: string; timestamp: string; latency_ms: number; status: number; }[];}SuperStyle client
Section titled “SuperStyle client”class SuperStyleClient { private baseUrl: string; private apiKey: string;
constructor(apiKey: string, baseUrl = "https://mcll3bnfubyazfg6wekv3xc6fi0dgpyk.lambda-url.us-east-1.on.aws") { this.apiKey = apiKey; this.baseUrl = baseUrl; }
private async request<T>(endpoint: string, options?: RequestInit): Promise<T> { const response = await fetch(`${this.baseUrl}${endpoint}`, { ...options, headers: { "X-API-Key": this.apiKey, "Content-Type": "application/json", ...options?.headers, }, });
if (!response.ok) { const error = await response.json(); throw new Error(error.error || `HTTP ${response.status}`); }
return response.json(); }
async identifyClothing(imageUrl: string): Promise<ClothingItem[]> { const data = await this.request<IdentifyClothingResponse>("/identify_clothing", { method: "POST", body: JSON.stringify({ image_url: imageUrl }), }); return data.items; }
async generateImage(params: GenerateImageRequest): Promise<GenerateImageResponse> { return this.request<GenerateImageResponse>("/generate_image", { method: "POST", body: JSON.stringify(params), }); }
async styleMe(params: StyleMeRequest): Promise<OutfitSuggestion[]> { const data = await this.request<StyleMeResponse>("/style_me", { method: "POST", body: JSON.stringify(params), }); return data.outfits; }
async usage(): Promise<UsageResponse> { return this.request<UsageResponse>("/usage"); }}Usage examples
Section titled “Usage examples”Identify clothing
Section titled “Identify clothing”const client = new SuperStyleClient("ss_your_key_here");
const items = await client.identifyClothing("https://example.com/outfit.jpg");
for (const item of items) { console.log(`${item.item}: ${item.color} — ${item.description}`); console.log(` Tags: ${item.style_tags.join(", ")}`); for (const product of item.products) { console.log(` Buy: ${product.title} (${product.price}) → ${product.url}`); }}Generate try-on image
Section titled “Generate try-on image”import { readFileSync, writeFileSync } from "fs";
const selfieBase64 = readFileSync("selfie.jpg").toString("base64");
const result = await client.generateImage({ selfie_base64: selfieBase64, clothing_description: "Black leather jacket with white t-shirt", mode: "studio",});
const imageBuffer = Buffer.from(result.image_base64, "base64");writeFileSync("tryon.jpg", imageBuffer);Style recommendations
Section titled “Style recommendations”const selfieBase64 = readFileSync("selfie.jpg").toString("base64");
const outfits = await client.styleMe({ selfie_base64: selfieBase64, style_preferences: "minimalist", occasion: "casual work", num_outfits: 3,});
for (const outfit of outfits) { console.log(`${outfit.style}: ${outfit.description}`); console.log(` Items: ${outfit.items.join(", ")}`);}Check usage
Section titled “Check usage”const stats = await client.usage();console.log(`Total: ${stats.total_requests} requests`);console.log(`Today: ${stats.requests_today} requests`);