Media segmentation

Find and cut out objects in images and video from a short text prompt. Name an object such as "yellow school bus", and get back the exact pixels for every match: a box that locates each object, and a mask you can measure, crop, or composite.

Segment Anything Model 3.1 (SAM 3.1) powers media segmentation on Meta Model API. One model, sam-3.1, segments both stills and clips over the Responses API, so one integration covers images and video. In video, SAM 3.1 follows each match across frames, so you can track an object through a clip.

When to use it

Use media segmentation when you need the pixel region of an object: it returns geometry — boxes and pixel-accurate masks. For a caption, an answer about a scene, or coordinates as text, use a Muse Spark model (a VLM) through image understanding or video understanding. The two pair well: let Muse Spark interpret a scene and decide what to segment, then hand the concept to SAM 3.1 for the masks.

Prompt with a short noun phrase. Text prompts only: name one concrete object per phrase, such as "delivery van" or "glasses". To segment several object types, send several requests.

What you can build

  • Image editing: mask an object to remove, blur, or replace its background.
  • Measurement and analytics: measure area, count instances, or pull regions out of photos, scans, or charts.
  • Video tracking: follow an object across frames to build highlight, redaction, or effects features.

Segment an image

Name an object and send an image over the Responses API. SAM 3.1 streams back a box and a mask for every match:

python
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.meta.ai/v1",
api_key=os.environ["MODEL_API_KEY"],
)
with client.responses.stream(
model="sam-3.1",
input=[
{
"type": "message",
"role": "user",
"content": [
{
"type": "input_text",
"text": "glasses",
},
{
"type": "input_image",
"image_url": "https://example.com/photo.png",
},
],
},
],
) as stream:
for event in stream:
if event.type == "response.output_text.delta":
print(event.delta, end="", flush=True)
print()

The response is special-token text: one box and one mask per match. See the SAM overview for the request and response in full, and reading segmentation output to parse it into geometry.

Next steps

The SAM section documents the model end to end: