# Watching

Tickets that admit a device to a stream on a relay, and the media keys that decrypt it.

Part of the [Celerbeam API and MCP reference](https://celerbeam.com/docs/api/index.md). HTML version: https://celerbeam.com/docs/api/watching/

## Get a Broadcast's media key

`GET /v1/organisations/{organisation_id}/broadcasts/{broadcast_id}/media-key`

The key that decrypts a live Broadcast's video. Only the User streaming it, or someone who holds a watch segment for it (from `issue_viewer_ticket`). Anyone else gets 403. Every read is a sensitive read, audited as `media_key.read`; the key is never in the event. Cache it per `stream_id`, so renewing a ticket doesn't read it again. A Broadcast that has ended gets 409 `not_live`.

- MCP tool: `get_broadcast_media_key` (read-only)
- Auth: Bearer token (`bearerAuth`)

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `organisation_id` | path | `OrganisationId` | yes | Organisation ID. |
| `broadcast_id` | path | `BroadcastId` | yes | Broadcast ID. |

### Responses

| Status | Description | Body |
| --- | --- | --- |
| 200 | The key. | `MediaKey` (`application/json`) |
| 400 | The request is malformed or fails validation (`invalid_request`), or an ID has the wrong prefix for its field (`invalid_id`). `errors` names each invalid field. | `Problem` (`application/problem+json`) |
| 401 | No valid bearer token (`unauthenticated`). Header `WWW-Authenticate`: The bearer challenge, per RFC 6750. | `Problem` (`application/problem+json`) |
| 403 | The caller can see the resource, but their Role doesn't allow this operation (`forbidden`). The attempt is audited with `result=denied`. | `Problem` (`application/problem+json`) |
| 404 | The resource doesn't exist, or the caller can't see it (`not_found`). The two are never told apart. | `Problem` (`application/problem+json`) |
| 409 | The change breaks a uniqueness rule or the resource's current state (`conflict`). | `Problem` (`application/problem+json`) |

## Issue a viewer ticket

`POST /v1/organisations/{organisation_id}/broadcasts/{broadcast_id}/viewer-tickets`

A ticket to watch a live Broadcast on one of the caller's devices, for 120 s. Ask again after `refresh_after`. Anyone with an active Membership: a Viewer's ticket is class `viewer`, with their Watermark code; a Member's or Admin's is class `team`, with none. The first ticket on a device starts a watch session (`watch_session.started`), and the first for each Broadcast a watch segment (`watch_segment.started`). A renewal records nothing, unless the caller's class has changed: then it starts a new segment. A Broadcast that has ended gets 409 `not_live`. A Viewer watches on one device at a time: their first ticket on a new device ends the watch sessions on their other devices (`watch_session.replaced`), and a sign-in from before that can then watch only on that device: elsewhere, its tickets get 409 `session_replaced` until the Viewer signs in again. Members and Admins are exempt.

- MCP tool: `issue_viewer_ticket` (not destructive)
- Auth: Bearer token (`bearerAuth`)

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `organisation_id` | path | `OrganisationId` | yes | Organisation ID. |
| `broadcast_id` | path | `BroadcastId` | yes | Broadcast ID. |

### Request body

`IssueViewerTicketRequest`, as `application/json`. Required.

### Responses

| Status | Description | Body |
| --- | --- | --- |
| 200 | The ticket, and where to use it. | `TicketBundle` (`application/json`) |
| 400 | The request is malformed or fails validation (`invalid_request`), or an ID has the wrong prefix for its field (`invalid_id`). `errors` names each invalid field. | `Problem` (`application/problem+json`) |
| 401 | No valid bearer token (`unauthenticated`). Header `WWW-Authenticate`: The bearer challenge, per RFC 6750. | `Problem` (`application/problem+json`) |
| 403 | The caller can see the resource, but their Role doesn't allow this operation (`forbidden`). The attempt is audited with `result=denied`. | `Problem` (`application/problem+json`) |
| 404 | The resource doesn't exist, or the caller can't see it (`not_found`). The two are never told apart. | `Problem` (`application/problem+json`) |
| 409 | The change breaks a uniqueness rule or the resource's current state (`conflict`). | `Problem` (`application/problem+json`) |

## Get an Uplink session's media key

`GET /v1/organisations/{organisation_id}/uplink-sessions/{uplink_session_id}/media-key`

The key that decrypts an Uplink session's Ready stream. The User streaming it, and Members, Admins and the Platform admin, who preview it. Every read is a sensitive read, audited as `media_key.read`; the key is never in the event. Cache it per `stream_id`. A session that has ended gets 409 `conflict`.

- MCP tool: `get_uplink_media_key` (read-only)
- Auth: Bearer token (`bearerAuth`)

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `organisation_id` | path | `OrganisationId` | yes | Organisation ID. |
| `uplink_session_id` | path | `UplinkSessionId` | yes | Uplink session ID. |

### Responses

| Status | Description | Body |
| --- | --- | --- |
| 200 | The key. | `MediaKey` (`application/json`) |
| 400 | The request is malformed or fails validation (`invalid_request`), or an ID has the wrong prefix for its field (`invalid_id`). `errors` names each invalid field. | `Problem` (`application/problem+json`) |
| 401 | No valid bearer token (`unauthenticated`). Header `WWW-Authenticate`: The bearer challenge, per RFC 6750. | `Problem` (`application/problem+json`) |
| 403 | The caller can see the resource, but their Role doesn't allow this operation (`forbidden`). The attempt is audited with `result=denied`. | `Problem` (`application/problem+json`) |
| 404 | The resource doesn't exist, or the caller can't see it (`not_found`). The two are never told apart. | `Problem` (`application/problem+json`) |
| 409 | The change breaks a uniqueness rule or the resource's current state (`conflict`). | `Problem` (`application/problem+json`) |

## Issue a preview ticket

`POST /v1/organisations/{organisation_id}/uplink-sessions/{uplink_session_id}/preview-tickets`

A ticket to preview an Uplink session's Ready stream on one of the caller's devices, for 120 s. Members, Admins and the Platform admin with a Membership. Always class `team`, and it starts no watch segment, because nothing is billed while Ready. The first ticket on a device starts a watch session (`watch_session.started`). A session that has ended gets 409 `conflict`.

- MCP tool: `issue_preview_ticket` (not destructive)
- Auth: Bearer token (`bearerAuth`)

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `organisation_id` | path | `OrganisationId` | yes | Organisation ID. |
| `uplink_session_id` | path | `UplinkSessionId` | yes | Uplink session ID. |

### Request body

`IssuePreviewTicketRequest`, as `application/json`. Required.

### Responses

| Status | Description | Body |
| --- | --- | --- |
| 200 | The ticket, and where to use it. | `TicketBundle` (`application/json`) |
| 400 | The request is malformed or fails validation (`invalid_request`), or an ID has the wrong prefix for its field (`invalid_id`). `errors` names each invalid field. | `Problem` (`application/problem+json`) |
| 401 | No valid bearer token (`unauthenticated`). Header `WWW-Authenticate`: The bearer challenge, per RFC 6750. | `Problem` (`application/problem+json`) |
| 403 | The caller can see the resource, but their Role doesn't allow this operation (`forbidden`). The attempt is audited with `result=denied`. | `Problem` (`application/problem+json`) |
| 404 | The resource doesn't exist, or the caller can't see it (`not_found`). The two are never told apart. | `Problem` (`application/problem+json`) |
| 409 | The change breaks a uniqueness rule or the resource's current state (`conflict`). | `Problem` (`application/problem+json`) |

## Get the ticket signing keys

`GET /v1/ticket-keys`

The Backend's Ed25519 public keys, by `key_id`, that relay tickets are signed with. The app checks each ticket's signature with them before it trusts what the ticket says, such as the Watermark code to draw. Any signed-in User. Public keys only; reading them records nothing.

- MCP tool: `get_ticket_keys` (read-only)
- Auth: Bearer token (`bearerAuth`)

### Responses

| Status | Description | Body |
| --- | --- | --- |
| 200 | The public keys. | `TicketKeys` (`application/json`) |
| 400 | The request is malformed or fails validation (`invalid_request`), or an ID has the wrong prefix for its field (`invalid_id`). `errors` names each invalid field. | `Problem` (`application/problem+json`) |
| 401 | No valid bearer token (`unauthenticated`). Header `WWW-Authenticate`: The bearer challenge, per RFC 6750. | `Problem` (`application/problem+json`) |
| 403 | The caller can see the resource, but their Role doesn't allow this operation (`forbidden`). The attempt is audited with `result=denied`. | `Problem` (`application/problem+json`) |

## Schemas

### OrganisationId

Organisation ID.

Type: `string`. Exactly 18 characters. Pattern `^ORG[a-z0-9]{15}$`. Example: `ORG8hfaw8hfpwhjf94`.

### BroadcastId

Broadcast ID.

Type: `string`. Exactly 18 characters. Pattern `^BRD[a-z0-9]{15}$`. Example: `BRD8hfaw8hfpwhjf94`.

### MediaKey

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `stream_id` | `StreamNumber` | yes | The stream's number on the wire (ADR 0004, "compact numeric stream numbers"). |
| `key_id` | `integer` | yes | Which key of the stream this is, as in each fragment's `key_id`. Always 1 for now. 1 to 255. |
| `key_b64` | `string` | yes | The 32-byte key, base64. Keep it in memory only, and cache it per `stream_id`. Pattern `^[A-Za-z0-9+/]{43}=$`. |

### StreamNumber

The stream's number on the wire (ADR 0004, "compact numeric stream numbers").

Type: `integer`. 1 to 4294967295.

### Problem

An RFC 9457 problem details object, sent as `application/problem+json`.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `type` | `string (uri-reference)` | yes | A URI identifying the problem type. `about:blank` when `code` says enough. Example: `about:blank`. |
| `title` | `string` | yes | A short, human-readable summary of the problem type. Example: `Not found`. |
| `status` | `integer` | yes | The HTTP status code. 400 to 599. Example: `404`. |
| `code` | `string` | yes | A stable, snake_case machine code. Clients branch on this, never on `title`. Pattern `^[a-z][a-z0-9]*(_[a-z0-9]+)*$`. Examples: `not_found`, `invalid_id`. |
| `detail` | `string` | no | A human-readable explanation of this occurrence. |
| `instance` | `string (uri-reference)` | no | The request path that produced the problem. |
| `request_id` | `string` | yes | Links the problem to the request logs and any audit event. |
| `started_by` | `UplinkSessionStarter` | no | `channel_in_use` only: who started the Channel's active Uplink session. |
| `reason` | `string` | no | `session_ended` only: `idle` (unused past its window) or `signed_out` (by another session, e.g. after a password change). One of `idle`, `signed_out`. |
| `errors` | `array of ProblemFieldError` | no | One entry per invalid field, for `invalid_request` and `invalid_id`. |
| `retry_after_seconds` | `integer` | no | `rate_limited` only: how long to wait before trying again, in seconds. At least 0. |

### UplinkSessionStarter

Who pressed Start.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `user_id` | `UserId` | yes | User ID. |
| `name` | `string` | yes | How to show them. Their email, until Users have names. Example: `mike@northgate.example`. |

### UserId

User ID.

Type: `string`. Exactly 18 characters. Pattern `^USR[a-z0-9]{15}$`. Example: `USR8hfaw8hfpwhjf94`.

### ProblemFieldError

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `pointer` | `string` | no | A JSON Pointer into the request body, e.g. `/first_admin_email`. |
| `parameter` | `string` | no | The name of the path, query or header parameter, e.g. `organisation_id`. |
| `detail` | `string` | yes | What is wrong with the field. |

### IssueViewerTicketRequest

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `device_id` | `DeviceId` | yes | The caller's own device, from `register_device`. |

### DeviceId

Device ID.

Type: `string`. Exactly 18 characters. Pattern `^DEV[a-z0-9]{15}$`. Example: `DEV8hfaw8hfpwhjf94`.

### TicketBundle

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `ticket_b64` | `string` | yes | The signed 188-byte ticket (C2), base64. Sent to the relay as it is, in `admit`. Pattern `^[A-Za-z0-9+/]{251}=$`. |
| `stream_id` | `StreamNumber` | yes | The stream's number on the wire (ADR 0004, "compact numeric stream numbers"). |
| `relay` | `TicketRelay` | yes | The relay to admit to, and its UDP address for this ticket (uplink for senders, downlink otherwise). |
| `expires_at` | `Timestamp` | yes | When the relay stops accepting the ticket. |
| `refresh_after` | `Timestamp` | yes | When to ask for the next ticket. |
| `watermark_code` | `WatermarkCode \| null` | yes | The Watermark code to draw, signed into the ticket. Viewer class only; `null` for senders and team. |
| `watermark_opacity` | `WatermarkOpacityValue \| null` | yes | How opaque to draw the Watermark code: the Organisation's `watermark_opacity`, from 0.3 to 1. With the code only; `null` for senders and team. The app never draws it below 0.3. |
| `watch_session_id` | `WatchSessionId \| null` | yes | The watch session, for viewer and preview tickets; `null` for a sender's. |
| `uplink_session_id` | `UplinkSessionId \| null` | yes | The Uplink session, for a sender's ticket; `null` otherwise. |
| `stream` | `TicketStream` | yes | Which stream the ticket is for. For a sender's ticket, the stream to send on right now: the Ready stream, or the live Broadcast's. |

### TicketRelay

The relay to admit to, and its UDP address for this ticket (uplink for senders, downlink otherwise).

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | yes | The relay's name in the Backend's configuration, e.g. `local-1`. 1 to 64 characters. |
| `host` | `string` | yes | 1 to 253 characters. |
| `port` | `integer` | yes | 1 to 65535. |

### Timestamp

UTC, with milliseconds and a `Z` suffix.

Type: `string (date-time)`. Pattern `^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$`. Example: `2026-11-28T14:27:03.412Z`.

### WatermarkCode

The 8-digit code drawn over the video for this Viewer, unique in the Organisation. It is not an ID (ADR 0004): people read it off a frame and type it in.

Type: `string`. Pattern `^[1-9][0-9]{7}$`. Example: `48207193`.

### WatermarkOpacityValue

How opaque the Watermark code is drawn, from 0.3 (the floor, C11's 30%) to 1 (opaque).

Type: `number`. 0.3 to 1. Example: `0.45`.

### WatchSessionId

Watch session ID.

Type: `string`. Exactly 18 characters. Pattern `^SSN[a-z0-9]{15}$`. Example: `SSN8hfaw8hfpwhjf94`.

### UplinkSessionId

Uplink session ID.

Type: `string`. Exactly 18 characters. Pattern `^UPL[a-z0-9]{15}$`. Example: `UPL8hfaw8hfpwhjf94`.

### TicketStream

Which stream the ticket is for. For a sender's ticket, the stream to send on right now: the Ready stream, or the live Broadcast's.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `kind` | `string` | yes | One of `ready`, `broadcast`. |
| `broadcast_id` | `BroadcastId \| null` | yes | The Broadcast, for a `broadcast` stream; `null` for the Ready stream. |

### IssuePreviewTicketRequest

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `device_id` | `DeviceId` | yes | The caller's own device, from `register_device`. |

### TicketKeys

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `keys` | `array of TicketKey` | yes | Every key a current ticket may be signed with. During a rotation the old and the new key are both listed (ADR 0010). |

### TicketKey

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `key_id` | `integer` | yes | The ticket's `signing_key_id` (C2) for tickets this key signs. 1 to 65535. |
| `public_key_b64` | `string` | yes | The raw 32-byte Ed25519 public key (RFC 8032), base64. Pattern `^[A-Za-z0-9+/]{43}=$`. |
