Segment the garments in a photo
/v2/models/segmentEvery 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.
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.
Request body
application/jsonrequiredThe model to run.
stylor-segment-v1The photo, as a base64 data URL (image/jpeg, image/png, image/webp) or a public https URL.
Look a second time, closer, where small jewellery may be. Slower; finds more of it.
Response
Response headers
X-RateLimit-ResourceThe 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-LimitRequests allowed in the current billing period, or unlimited.
X-RateLimit-Quota-RemainingRequests left in the current billing period, or unlimited.
X-RateLimit-Quota-ResetUnix epoch seconds at which the billing period resets.
X-RateLimit-RPM-LimitRequests allowed per minute for this resource.
X-RateLimit-RPM-RemainingRequests left in the current one-minute window.
X-RateLimit-RPM-ResetUnix epoch seconds at which the one-minute window resets.
The model that answered, by its public name.
The upright photo's width in pixels.
The upright photo's height in pixels.
The items found, in paint order. Empty when the photo has none.
The item's class, category/type. One of 68 classes; other is an item the model sees but cannot name.
The part of label before the slash.
accessorybagbottomeyewearfootwearfull bodyheadwearhosieryjewelleryouterwearsleepwearswimweartopunderwearotherThe part of label after the slash.
[x0, y0, x1, y1] in pixels of the upright photo; x1 and y1 are exclusive.
The mask's pixels.
A 1-bit PNG data URL the size of the photo, white where the item is.
Where the time went, in milliseconds.
Reading and preparing the photo.
Running the model
Errors
34Every error is JSON with a single error string unless noted. Match on the status code; the message is for humans.
Request body must be valid JSON.The body is not parseable JSON.
Request body must be a JSON object.The body is JSON but not an object (an array, a string, null).
image is too large.The data URL is over 8 million characters, or the fetched photo is over 12 MB.
model must be one of: stylor-segment-v1.model is not a string, or not a model this endpoint serves.
image is required: a base64 data URL (png, jpeg or webp) or a public https URL.image is missing, empty or not a string.
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.
image: a URL can be at most 2048 characters.image is a URL longer than 2048 characters.
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.
image could not be fetched.The URL did not answer with 2xx within 10 seconds, redirected, or resolved to a private address.
image is not an image.The URL answered with text, JSON or XML.
image is empty.The data URL or the fetched file has no bytes.
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.
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.
zoom must be true or false.zoom is not a boolean.
The model failed to answer. Try again.The model failed on this request. Safe to retry.
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.
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.
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"
}'{
"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
}
}