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

Authorizations

Authorization
string
headerrequired

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

multipart/form-data
image
file
required

Image to segment.

model_id
string
default: facebook/sam2-hiera-large

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
default: true

If true, the model will return three masks for ambiguous input prompts, often producing better masks than a single prediction.

return_logits
boolean
default: true

If true, returns un-thresholded mask logits instead of a binary mask.

normalize_coords
boolean
default: true

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 - application/json

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.