Python SDK
Use the SuperStyle API from Python with the requests library.
Installation
Section titled “Installation”pip install requestsQuick example
Section titled “Quick example”import requests
API_KEY = "ss_your_key_here"BASE_URL = "https://mcll3bnfubyazfg6wekv3xc6fi0dgpyk.lambda-url.us-east-1.on.aws"
headers = { "X-API-Key": API_KEY, "Content-Type": "application/json",}
# Identify clothing in an imageresponse = requests.post( f"{BASE_URL}/analyze_outfit", headers=headers, json={"image_url": "https://example.com/outfit.jpg"})
data = response.json()for item in data["items"]: print(f"{item['item']}: {item['color']} — {item['description']}") for product in item.get("products", []): print(f" Buy: {product['title']} ({product.get('price', 'N/A')}) → {product['url']}")SuperStyle client class
Section titled “SuperStyle client class”A minimal wrapper for convenience:
import requestsimport base64from pathlib import Path
class SuperStyleClient: def __init__(self, api_key: str, base_url: str = "https://mcll3bnfubyazfg6wekv3xc6fi0dgpyk.lambda-url.us-east-1.on.aws"): self.base_url = base_url self.headers = { "X-API-Key": api_key, "Content-Type": "application/json", }
def _post(self, endpoint: str, data: dict) -> dict: response = requests.post( f"{self.base_url}{endpoint}", headers=self.headers, json=data, ) response.raise_for_status() return response.json()
def _get(self, endpoint: str) -> dict: response = requests.get( f"{self.base_url}{endpoint}", headers=self.headers, ) response.raise_for_status() return response.json()
def analyze_outfit(self, image_url: str) -> list[dict]: """Analyze an outfit image and return identified items.""" data = self._post("/analyze_outfit", {"image_url": image_url}) return data["items"]
def try_on_outfit( self, selfie_path: str, clothing_description: str, mode: str = "model_shot", clothing_image_url: str | None = None, outfit_path: str | None = None, store_image: bool = False, ) -> tuple[str, str]: """Generate a try-on image. Returns (image_url, mime_type).
Provide a reference outfit via clothing_image_url (URL) or outfit_path (local file, sent as base64). If both are given, outfit_path takes priority.
Note: image auto-deletes after 24 hours unless store_image=True. """ selfie_b64 = base64.b64encode(Path(selfie_path).read_bytes()).decode() payload = { "selfie_base64": selfie_b64, "clothing_description": clothing_description, "mode": mode, "store_image": store_image, } if outfit_path: payload["outfit_base64"] = base64.b64encode(Path(outfit_path).read_bytes()).decode() elif clothing_image_url: payload["clothing_image_url"] = clothing_image_url
data = self._post("/try_on_outfit", payload) return data["image_url"], data["mime_type"]
def style_me( self, selfie_path: str, style_preferences: str | None = None, occasion: str | None = None, num_outfits: int = 3, ) -> list[dict]: """Get personalized outfit suggestions.""" selfie_b64 = base64.b64encode(Path(selfie_path).read_bytes()).decode() payload = {"selfie_base64": selfie_b64, "num_outfits": num_outfits} if style_preferences: payload["style_preferences"] = style_preferences if occasion: payload["occasion"] = occasion
data = self._post("/style_me", payload) return data["outfits"]
def usage(self) -> dict: """Get API usage statistics.""" return self._get("/usage")Handling rate limits
Section titled “Handling rate limits”All endpoints except /usage are limited to 20 requests/day per user with 1 concurrent request. Handle 429 responses with retry logic:
import time
def call_with_retry(func, *args, max_retries=3, **kwargs): for attempt in range(max_retries): try: return func(*args, **kwargs) except requests.HTTPError as e: if e.response.status_code == 429: retry_after = int(e.response.headers.get("Retry-After", 30)) print(f"Rate limited. Retrying in {retry_after}s...") time.sleep(retry_after) else: raise raise Exception("Max retries exceeded")
# Usageimage_url, mime = call_with_retry(client.try_on_outfit, selfie_path="selfie.jpg", clothing_description="Black leather jacket",)client = SuperStyleClient("ss_your_key_here")
# Identify clothingitems = client.analyze_outfit("https://example.com/outfit.jpg")
# Generate try-on — auto-deletes after 24 hoursimage_url, mime_type = client.try_on_outfit( selfie_path="selfie.jpg", clothing_description="Black leather jacket", mode="model_shot",)# Download immediately before the URL expiresimg_response = requests.get(image_url)with open("tryon.jpg", "wb") as f: f.write(img_response.content)
# Get style recommendationsoutfits = client.style_me("selfie.jpg", occasion="date night")for outfit in outfits: print(outfit["description"]) # Download each try-on image img = requests.get(outfit["image_url"]) with open(f"outfit-{outfit['style']}.jpg", "wb") as f: f.write(img.content)
# Check usagestats = client.usage()print(f"Total requests: {stats['total_requests']}")