---
title: "Segment Anything 2"
method: POST
path: "/api/generate/segment-anything-2"
tags: ["generate"]
---

# Segment Anything 2

`POST /api/generate/segment-anything-2`

## Request

- The document declares no server URL.
- Auth: none declared

Segment objects in an image.

## Request body `multipart/form-data`

- BodyGenSegmentAnything2
  - `image` string, binary, required: Image to segment.
  - `model_id` string: Hugging Face model ID used for image generation.
  - `point_coords` string: Nx2 array of point prompts to the model, where each point is in (X,Y) in pixels.
  - `point_labels` string: Labels for the point prompts, where 1 indicates a foreground point and 0 indicates a background point.
  - `box` string: A length 4 array given as a box prompt to the model, in XYXY format.
  - `mask_input` string: A low-resolution mask input to the model, typically from a previous prediction iteration, with the form 1xHxW (H=W=256 for SAM).
  - `multimask_output` boolean: If true, the model will return three masks for ambiguous input prompts, often producing better masks than a single prediction.
  - `return_logits` boolean: If true, returns un-thresholded mask logits instead of a binary mask.
  - `normalize_coords` boolean: If true, the point coordinates will be normalized to the range [0,1], with point_coords expected to be with respect to image dimensions.

## Response `200`

Successful Response

- MasksResponse: Response model for object segmentation.
  - `masks` string, required: The generated masks.
  - `scores` string, required: The model's confidence scores for each generated mask.
  - `logits` string, required: The raw, unnormalized predictions (logits) for the masks.

## Other responses

- `400`: Bad Request
- `401`: Unauthorized
- `422`: Validation Error
- `500`: Internal Server Error
- `default`: Error

## Changes

- **2025-10-30** `dfc937fc0d2c`: 6 breaking, 3 info
  - the `oneOf[subschema #1: HTTPError]/detail` response's property type changed from `object` to no type for status `400`
  - the `oneOf[subschema #1: HTTPError]/detail` response's property type changed from `object` to no type for status `401`
  - the `oneOf[subschema #1: HTTPError]/detail` response's property type changed from `object` to no type for status `500`
  - removed the required property `oneOf[subschema #1: HTTPError]/detail/msg` from the response with the `400` status
  - …5 more
- **2025-10-30** `f5d01b71ba9a`: 3 breaking, 6 info
  - the `oneOf[subschema #1: HTTPError]/detail` response's property type changed from no type to `object` for status `400`
  - the `oneOf[subschema #1: HTTPError]/detail` response's property type changed from no type to `object` for status `401`
  - the `oneOf[subschema #1: HTTPError]/detail` response's property type changed from no type to `object` for status `500`
  - removed `#/components/schemas/APIError` from the `oneOf[subschema #1: HTTPError]/detail` response property `allOf` list for the response status `400`
  - …5 more
- **2024-10-03** `cbf999b9a7cf`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/livepeer/apis/livepeer-ai-api/changes/api/generate/segment-anything-2/post.md)

---

[API](https://skmtc.dev/livepeer/apis/livepeer-ai-api.md) - [All operations](https://skmtc.dev/livepeer/apis/livepeer-ai-api/llms.txt) - [OpenAPI document](https://skmtc.dev/livepeer/apis/livepeer-ai-api/revisions/dfc937fc0d2c?raw)
