# Detect objects

> Find objects by name in an image and get a labelled box for each.

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

## 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 detection model to run, e.g. `idea-research/grounding-dino`. 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.
- `labels` (string[], required): What to look for, e.g. `["cup", "bowl"]`. 1–50 names, each up to 200 characters.

## Response

- `id` (string): Unique id of this call, e.g. `det_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.
- `detections` (object[]): One per object found.
  - `label` (string): Which of your labels it matched.
  - `score` (number): Confidence, 0–1.
  - `box` (number[4]): `[x0, y0, x1, y1]` in pixels.
- `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/detect",
  headers={"Authorization": f"Bearer {os.environ['OPENROBOTICS_API_KEY']}"},
  json={
    "model": "idea-research/grounding-dino",
    "image": "<base64 JPEG or PNG>",
    "labels": ["cup", "bowl"],
  },
).json()
res["detections"]       # label, score, box
```

TypeScript:

```typescript
const res = await fetch("https://api.openrobotics.dev/v1/detect", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.OPENROBOTICS_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "idea-research/grounding-dino",
    image: "<base64 JPEG or PNG>",
    labels: ["cup", "bowl"],
  }),
}).then((r) => r.json());
```

cURL:

```bash
curl https://api.openrobotics.dev/v1/detect \
  -H "Authorization: Bearer $OPENROBOTICS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"idea-research/grounding-dino","image":"<base64 JPEG or PNG>","labels":["cup","bowl"]}'
```

## Example response

```json
{
  "id": "det_48213",
  "model": "idea-research/grounding-dino",
  "backend": "http",
  "detections": [
    {
      "label": "cup",
      "score": 0.87,
      "box": [212.4, 140.1, 318.9, 266]
    },
    {
      "label": "bowl",
      "score": 0.71,
      "box": [380.2, 220.5, 520, 330.8]
    }
  ],
  "usage": { "cost_usd": 0.0001, "latency_ms": 140 }
}
```

## Models

7 live for `/detect`:

- [Grounding DINO](https://www.openrobotics.dev/models/idea-research/grounding-dino.md): `idea-research/grounding-dino`, $0.10 per 1,000 calls
- [OWLv2](https://www.openrobotics.dev/models/google/owlv2.md): `google/owlv2`, $0.10 per 1,000 calls
- [Florence-2](https://www.openrobotics.dev/models/microsoft/florence-2.md): `microsoft/florence-2`, $0.10 per 1,000 calls
- [RF-DETR](https://www.openrobotics.dev/models/roboflow/rf-detr.md): `roboflow/rf-detr`, $0.10 per 1,000 calls
- [LLMDet](https://www.openrobotics.dev/models/isee/llmdet.md): `isee/llmdet`, $0.10 per 1,000 calls
- [OmDet-Turbo](https://www.openrobotics.dev/models/omlab/omdet-turbo.md): `omlab/omdet-turbo`, $0.10 per 1,000 calls
- [D-FINE](https://www.openrobotics.dev/models/ustc/d-fine.md): `ustc/d-fine`, $0.10 per 1,000 calls
