# Segment objects

> Get object masks for an image from point, box or text prompts.

`POST https://api.openrobotics.dev/v1/segment`

Send at least one prompt. Text prompts return a mask for every instance of the concept, each labelled with the text it answers.

## Authorization

`Authorization: Bearer sk-orb-v1-…`, your [API key](https://www.openrobotics.dev/docs/authentication), or a free [test key](https://www.openrobotics.dev/docs/authentication#test-keys) (`sk-orb-test-…`; no account? get one with [`POST /sandbox/keys`](https://www.openrobotics.dev/docs/api/create-sandbox-key)).

## Request body

JSON, with `Content-Type: application/json`.

- `model` (string, required): The segmentation model to run, e.g. `meta/sam-3`. The live models for this endpoint are listed below.
- `image` (string, required): The image, base64 JPEG or PNG (a `data:` URL works too). Under 4 MB of base64.
- `points` (number[][]): Up to 32 `[x, y]` pixel positions on the object.
- `boxes` (number[][]): Up to 32 boxes, each `[x0, y0, x1, y1]` in pixels.
- `text` (string | string[]): What to find, e.g. `"red cup"`, or up to 16 phrases. For models that take text (e.g. SAM 3).

## Response

- `id` (string): Unique id of this call, e.g. `seg_48213`. It matches the call in your Activity dashboard.
- `model` (string): The model that answered.
- `backend` (string): `"http"`: the real model ran on a GPU. `"simulated"`: stand-in output of the same shape, as test keys get.
- `sandbox` (boolean): `true` when the call was made with a [test key](https://www.openrobotics.dev/docs/authentication#test-keys): the output is simulated, nothing ran on a GPU and nothing was charged. Absent otherwise.
- `masks` (object[]): One per object found.
  - `score` (number): Confidence, 0–1.
  - `box` (number[4]): The mask's bounding box, `[x0, y0, x1, y1]` in pixels.
  - `area` (integer): Mask area in pixels.
  - `rle` (object): The mask as uncompressed COCO RLE: `{ size: [height, width], counts }`, column-major (the format `pycocotools` decodes).
  - `text` (string): For text prompts: the phrase this mask answers.
- `usage` (object): What the call cost.
  - `cost_usd` (number): Charged to your credits, in US dollars.
  - `latency_ms` (integer): Time the model took, in milliseconds.

## Errors

Plus the errors every endpoint shares: see [Errors](https://www.openrobotics.dev/docs/errors).

## Example request

Python:

```python
import os, requests

res = requests.post(
  "https://api.openrobotics.dev/v1/segment",
  headers={"Authorization": f"Bearer {os.environ['OPENROBOTICS_API_KEY']}"},
  json={
    "model": "meta/sam-3",
    "image": "<base64 JPEG or PNG>",
    "text": "red cup",
  },
).json()
res["masks"][0]["rle"]  # COCO RLE mask
```

TypeScript:

```typescript
const res = await fetch("https://api.openrobotics.dev/v1/segment", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.OPENROBOTICS_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "meta/sam-3",
    image: "<base64 JPEG or PNG>",
    text: "red cup",
  }),
}).then((r) => r.json());
```

cURL:

```bash
curl https://api.openrobotics.dev/v1/segment \
  -H "Authorization: Bearer $OPENROBOTICS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"meta/sam-3","image":"<base64 JPEG or PNG>","text":"red cup"}'
```

## Example response

```json
{
  "id": "seg_48213",
  "model": "meta/sam-3",
  "backend": "http",
  "masks": [
    {
      "text": "red cup",
      "score": 0.93,
      "box": [212.4, 140.1, 318.9, 266],
      "area": 10512,
      "rle": { "size": [480, 640], "counts": [135822, 41, 437, …] }
    }
  ],
  "usage": { "cost_usd": 0.0001, "latency_ms": 180 }
}
```

## Models

7 live for `/segment`:

- [SAM 2](https://www.openrobotics.dev/models/meta/sam-2.md): `meta/sam-2`, $0.10 per 1,000 calls
- [SAM 3](https://www.openrobotics.dev/models/meta/sam-3.md): `meta/sam-3`, $0.10 per 1,000 calls
- [Segment Anything (SAM)](https://www.openrobotics.dev/models/meta/sam.md): `meta/sam`, $0.10 per 1,000 calls
- [Grounded SAM 2](https://www.openrobotics.dev/models/idea-research/grounded-sam-2.md): `idea-research/grounded-sam-2`, $0.10 per 1,000 calls
- [EfficientSAM3](https://www.openrobotics.dev/models/bristol/efficientsam3.md): `bristol/efficientsam3`, $0.10 per 1,000 calls
- [Sa2VA (Qwen3-VL-4B)](https://www.openrobotics.dev/models/bytedance/sa2va.md): `bytedance/sa2va`, $0.10 per 1,000 calls
- [EdgeTAM](https://www.openrobotics.dev/models/meta/edgetam.md): `meta/edgetam`, $0.10 per 1,000 calls
