Skip to main content
Segment an image with SAM-3.1 using exactly one prompt type.
Input images up to 1280 x 720 (width x height). Larger images are rejected with HTTP 413, not downscaled — resize first.

Parameters

ImageInput
required
RGB image as file path, URL, PIL Image, or numpy array.
Optional[str]
Text prompt describing objects to segment (exclusive with points/boxes).
Optional[Iterable[Iterable[float]]]
List of [x, y] point coordinates (exclusive with text/boxes).
Optional[Iterable[Iterable[float]]]
List of [x0, y0, x1, y1] box coordinates (exclusive with text/points).
Optional[Iterable[int]]
Required for points/boxes. 1=foreground, 0=background.
Optional[float]
Optional HTTP timeout in seconds.

Returns

np.ndarray: Binary segmentation mask as numpy array (H, W) with dtype uint8. Foreground pixels are 255, background pixels are 0.

Example