> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.labric.co/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.labric.co/_mcp/server.

# Save annotations on an image

POST https://platform.labric.co/api/v1/images/{file_id}/annotations
Content-Type: application/json

Save masks on an image as annotations, one per entry.

Each entry is a binary mask PNG (white-on-transparent, base64-encoded)
for a label; labels are created on first use. Saving is additive, so
a label can accumulate several masks on the same image. The annotations
a segmentation model returns from predict can be passed straight through;
each names the file it was predicted for, and one for a different file
rejects the request. Leave is_human_vetted false for automated saves:
the mask editor flags unvetted masks for review, and only vetted masks
feed training. The file must be a processed image. All-or-nothing: one
bad entry rejects the whole request.

Requires an API key with the `write` scope.

Reference: https://docs.labric.co/api-reference/labric-api/images/annotate

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Request

### Path parameters

- `file_id` (string, required)

### Body (application/json)

This endpoint expects an object.

- `annotations` (list of object, required)
  - `mask` (string, required)
  - `label` (string, required)
  - `width` (integer, optional, nullable)
  - `height` (integer, optional, nullable)
  - `is_human_vetted` (boolean, optional, default: false)
  - `file_id` (string, optional, nullable)

## Response

### 200

OK

- `list of object`
  - `id` (string, required)
  - `label` (string, required)
  - `mask_url` (string, optional, nullable)
  - `width` (integer, optional, nullable)
  - `height` (integer, optional, nullable)
  - `is_human_vetted` (boolean, optional, default: false)
  - `foreground_fraction` (double, optional, nullable)

## Errors

### 400 Bad Request Error

Bad Request

- `detail` (string, required)

### 401 Unauthorized Error

Unauthorized

- `detail` (string, required)

### 403 Forbidden Error

Forbidden

- `detail` (string, required)

### 404 Not Found Error

Not Found

- `detail` (string, required)

### 422 Unprocessable Entity Error

Unprocessable Content

- `detail` (list of map from string to any, required)

### 500 Internal Server Error

Internal Server Error

- `detail` (string, required)

### 502 Bad Gateway Error

Bad Gateway

- `detail` (string, required)

## Examples

**Request**

```json
{
  "annotations": [
    {
      "mask": "R0lGODlhAQABAIAAAAUEBA==",
      "label": "grain_boundary",
      "width": 2048,
      "height": 1536,
      "is_human_vetted": false
    }
  ]
}
```

**Response**

```json
[
  {
    "id": "7c6d5e4f-3a2b-4c1d-9e8f-0a1b2c3d4e5f",
    "label": "grain_boundary",
    "mask_url": "https://storage.googleapis.com/labric-images/annotations/5d4c3b2a-1f0e-4d9c-8b7a-6f5e4d3c2b1a/7c6d5e4f-3a2b-4c1d-9e8f-0a1b2c3d4e5f.png?signature=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9",
    "width": 2048,
    "height": 1536,
    "is_human_vetted": false,
    "foreground_fraction": 0.12
  }
]
```

**SDK Code**

```python
from labric import Labric, SaveAnnotationSchema

client = Labric(
    api_key="YOUR_TOKEN_HERE",
)

client.images.annotate(
    file_id="5d4c3b2a-1f0e-4d9c-8b7a-6f5e4d3c2b1a",
    annotations=[
        SaveAnnotationSchema(
            mask="R0lGODlhAQABAIAAAAUEBA==",
            width=2048,
            height=1536,
            label="grain_boundary",
            is_human_vetted=False,
        )
    ],
)

```