Hat and cap try-on API: one selfie, one call per colorway

Let shoppers see a cap or beanie on their own head: one selfie plus one product photo per colorway, a cache key per shopper, SKU and colour, and a cost log.

4 min readSume
All posts

Headwear is an easy accessory to preview: the face stays visible and the item covers only a small area. ChatGPT Try On, launched 1 October 2026 with a selfie or full-body photo as input (TechCrunch, read 2026-10-04), covers accessories in general. For a shop that sells caps, the question is how to run that inside the product page, per colorway.

The pattern on Sume is one image edit per colorway, each with the shopper's selfie and that colorway's product photo as two references.

One call per colour

Keep the loop outside the model. A shopper who taps the navy, olive and sand caps triggers three requests, each with its own product photo. That keeps every result tied to a specific SKU and colour, which a single prompt listing three colours cannot promise.

import os, requests

H = {"Authorization": f"Bearer {os.environ['SUME_API_KEY']}"}
resp = requests.post("https://api.sume.com/v1/images", headers=H, timeout=90, json={
    "model": "openai/gpt-image-2.5",
    "prompt": "Image 1 is the shopper. Image 2 is a navy baseball cap. Put the cap on the shopper's head, brim forward, sitting naturally over the hair. Keep the logo on the cap as in image 2. Keep face, clothing and background from image 1.",
    "input_references": [
        {"type": "image_url", "image_url": {"url": "https://example.com/selfie.jpg"}},
        {"type": "image_url", "image_url": {"url": "https://example.com/cap-navy.jpg"}}
    ],
    "aspect_ratio": "auto",
})
resp.raise_for_status()
if resp.status_code == 202:
    raise SystemExit("job envelope: poll data.status_url")
body = resp.json()
print([d["url"] for d in body["data"]], body.get("usage"))

Idempotency and cost

Retries happen when a shopper double-taps. On Sume, POST /v1/images blocks for up to 30 seconds and returns the images, or returns a 202 job envelope after that. For the video endpoints Sume documents an Idempotency-Key header; for images, make your own key from shopper id, SKU and colour and cache the first result under it, so a double tap costs one call.

Log usage.cost from each response against the same key, and cap the colours per session so one shopper cannot run a long chain.

What to check

  • The logo is the same size and position as on the product photo.
  • Hair is not cut off or turned into a hat texture.
  • The brim does not cover the eyes unless the product is meant to.
  • The shopper's face is unchanged between the colour variants.

Sources

Related posts

More in Use cases

All Use cases posts

Written by Sume