Segment the garments in a photo

post/v2/models/segment

Every garment and accessory in a photo, each with its label, its box and its mask. Works on photos of people dressed and on product shots.

Send the photo as image: a base64 data URL (image/jpeg, image/png or image/webp) or a public https URL the server fetches (no redirects, at most 12 MB). The photo is read in memory and dropped, never stored or logged. It is turned upright (EXIF) first; width and height in the response are the upright photo's, and every box and mask is in that frame.

Masks never overlap: a pixel belongs to at most one item. Each mask is a 1-bit PNG data URL the size of the photo, white where the item is.

zoom: true looks a second time, closer, where small jewellery may be. It finds more rings, earrings and necklaces and takes about three times as long.

bash
curl https://stylor.ai/api/v2/models/segment \
  -H "Authorization: Bearer $STYLOR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "model": "stylor-segment-v1", "image": "https://example.com/look.jpg" }'

A request normally answers in about a second. When the model is not ready to take the request, the endpoint answers 503 with a Retry-After header; send the same request again after that many seconds. A 5xx answer never uses quota.

It is metered on api.v2.models.segment. The demo key cannot call it.

Public keyapi.v2.models.segmentNo demo

Request body

application/jsonrequired
modelstring

The model to run.

One ofstylor-segment-v1
default: "stylor-segment-v1"
imagestringrequired

The photo, as a base64 data URL (image/jpeg, image/png, image/webp) or a public https URL.

e.g. "https://example.com/look.jpg"
zoomboolean

Look a second time, closer, where small jewellery may be. Slower; finds more of it.

default: false

Response

200The items found.

Response headers

X-RateLimit-Resource

The quota resource this endpoint is metered against: api.v2.models.segment for the segment endpoint. Each model endpoint has its own resource, separate from the v1 and Agent API resources.

X-RateLimit-Quota-Limit

Requests allowed in the current billing period, or unlimited.

X-RateLimit-Quota-Remaining

Requests left in the current billing period, or unlimited.

X-RateLimit-Quota-Reset

Unix epoch seconds at which the billing period resets.

X-RateLimit-RPM-Limit

Requests allowed per minute for this resource.

X-RateLimit-RPM-Remaining

Requests left in the current one-minute window.

X-RateLimit-RPM-Reset

Unix epoch seconds at which the one-minute window resets.

modelstringrequired

The model that answered, by its public name.

widthintegerrequired

The upright photo's width in pixels.

heightintegerrequired

The upright photo's height in pixels.

array<SegmentItem>required

The items found, in paint order. Empty when the photo has none.

labelstringrequired

The item's class, category/type. One of 68 classes; other is an item the model sees but cannot name.

e.g. "outerwear/jacket"
categorystringrequired

The part of label before the slash.

One ofaccessorybagbottomeyewearfootwearfull bodyheadwearhosieryjewelleryouterwearsleepwearswimweartopunderwearother
typestringrequired

The part of label after the slash.

e.g. "jacket"
boxarray<integer>required

[x0, y0, x1, y1] in pixels of the upright photo; x1 and y1 are exclusive.

minItems: 4maxItems: 4
areaintegerrequired

The mask's pixels.

maskstringrequired

A 1-bit PNG data URL the size of the photo, white where the item is.

objectrequired

Where the time went, in milliseconds.

totalinteger
photointeger

Reading and preparing the photo.

modelinteger

Running the model

Errors

34

Every error is JSON with a single error string unless noted. Match on the status code; the message is for humans.

400
Request body must be valid JSON.

The body is not parseable JSON.

400
Request body must be a JSON object.

The body is JSON but not an object (an array, a string, null).

413
image is too large.

The data URL is over 8 million characters, or the fetched photo is over 12 MB.

422
model must be one of: stylor-segment-v1.

model is not a string, or not a model this endpoint serves.

422
image is required: a base64 data URL (png, jpeg or webp) or a public https URL.

image is missing, empty or not a string.

422
image must be a base64 data URL (png, jpeg or webp).

image starts with data: but is not a base64 PNG, JPEG or WebP data URL.

422
image: a URL can be at most 2048 characters.

image is a URL longer than 2048 characters.

422
image: <reason>

image is a URL that is not a public http(s) address: an IP address, an internal host, or not a URL at all.

422
image could not be fetched.

The URL did not answer with 2xx within 10 seconds, redirected, or resolved to a private address.

422
image is not an image.

The URL answered with text, JSON or XML.

422
image is empty.

The data URL or the fetched file has no bytes.

422
image could not be read as a JPEG, PNG or WebP photo.

The bytes are not a readable JPEG, PNG or WebP (whatever the data URL or the server called them), or the image is over 40 million pixels.

422
image is too small: its shorter edge must be at least 64 pixels, and its longer edge at most 64 times its shorter.

The photo's shorter edge is under 64 pixels, or the photo is more than 64 times longer than it is wide.

422
zoom must be true or false.

zoom is not a boolean.

502
The model failed to answer. Try again.

The model failed on this request. Safe to retry.

503
The model is starting. Try again in a few seconds.

The model was not ready within 25 seconds. Retry-After gives the seconds to wait.

503
The model is busy. Try again in a few seconds.

The model cannot take more requests for the moment. Retry-After gives the seconds to wait.

503
This model is not available yet.

The model is not deployed in this environment.

curl -X POST "https://stylor.ai/api/v2/models/segment" \
  -H "Authorization: Bearer $STYLOR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "stylor-segment-v1",
  "image": "https://example.com/look.jpg"
}'
Response · 200
{
  "model": "stylor-segment-v1",
  "width": 930,
  "height": 1395,
  "items": [
    {
      "label": "top/t shirt",
      "category": "top",
      "type": "t shirt",
      "box": [
        311,
        366,
        391,
        673
      ],
      "area": 9993,
      "mask": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
    },
    {
      "label": "outerwear/jacket",
      "category": "outerwear",
      "type": "jacket",
      "box": [
        104,
        290,
        899,
        1190
      ],
      "area": 473186,
      "mask": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
    }
  ],
  "ms": {
    "total": 612,
    "photo": 38,
    "model": 561
  }
}