{"openapi":"3.1.0","info":{"title":"OpenMV Live Relay","version":"1.0.0","description":"Live viewing for OpenMV cameras. A camera holds one outbound WebSocket and pushes frames; up to 16 viewers subscribe to the same room and every frame fans out at the edge, so the camera uploads each frame once no matter how many dashboards are watching.\n\n## Rooms\n\nA room is one `{device_id}/{stream}` pair. Cameras publish into it, viewers read from it, and nothing is stored: a viewer sees frames from the moment it connects.\n\n## Authentication\n\nEvery endpoint takes a token issued by OpenMV Cloud and scoped to one device, with a lifetime measured in minutes. Cameras only ever connect outward; nothing connects to a camera.\n\nA socket lasts only as long as the token that opened it: when the token runs out the relay closes the socket with code 4001, and the caller reconnects with a fresh one.\n\nSend it as `Authorization: Bearer <token>`. A browser cannot set headers on a WebSocket, so from a browser offer it as the second subprotocol: `new WebSocket(url, [\"openmv.bearer\", token])` -- the relay answers with `openmv.bearer`. `?token=` is still accepted for cameras already in the field, but a URL is the one place a credential is guaranteed to be written down, so prefer either of the other two.\n\nManage cameras and watch them at [cloud.openmv.io](https://cloud.openmv.io)."},"servers":[{"url":"https://live.cloud.openmv.io"}],"components":{"securitySchemes":{"cameraToken":{"type":"http","scheme":"bearer","description":"The camera's own capability token, minted by the update server and handed to the device in its check-in answer. It authenticates the {device_id} segment and covers both publishing and polling, so a camera needs exactly one credential. Sent as `Authorization: Bearer <token>`; the `openmv.bearer` subprotocol and `?token=` carry the same value."},"viewerToken":{"type":"http","scheme":"bearer","description":"A short-lived viewer token from the update server's `POST /api/v1/admin/devices/{device_id}/viewer-grant` (one camera) or `POST /api/v1/admin/products/{product_id}/viewer-grant` (every camera of a product). It expires in minutes, and a socket it opened is closed when it does, so fetch a fresh one for every connection rather than caching it."}}},"tags":[{"name":"Camera","description":"Called by the camera in the field."},{"name":"Viewer","description":"Called by a dashboard watching a camera."},{"name":"Health","description":"Liveness probe."}],"paths":{"/camera/{device_id}/{stream}":{"get":{"security":[{"cameraToken":[]}],"tags":["Camera"],"summary":"Publish a stream","description":"Opens the camera's side of the room. The camera then sends **binary frames**, and receives JSON control messages as viewers come and go: `{\"type\":\"start\"}` when the first viewer arrives and `{\"type\":\"stop\"}` when the last one leaves, so a camera can stay idle while nobody is watching.\n\nOne camera per room: a second connection replaces the first, which is closed with code 1012. When the token runs out the socket is closed with code 4001; reconnect with the token from the latest check-in.","parameters":[{"name":"device_id","in":"path","required":true,"description":"The camera's device id, as registered with OpenMV Cloud.","schema":{"type":"string","pattern":"^[A-Za-z0-9_:.-]{1,128}$"}},{"name":"stream","in":"path","required":true,"description":"Which image stream on that camera. A device has one credential but any number of streams (a multi-camera board, or virtual streams an app defines); the default stream is named \"0\".","schema":{"type":"string","pattern":"^[A-Za-z0-9_.-]{1,64}$"}}],"responses":{"101":{"description":"Switching Protocols: the WebSocket is open."},"403":{"description":"The token is missing, malformed, expired, or not for this device."},"404":{"description":"No such path: the device or stream segment is malformed."},"426":{"description":"Upgrade Required: this path only answers a WebSocket upgrade."}}}},"/watch/{device_id}/{stream}":{"get":{"security":[{"viewerToken":[]}],"tags":["Viewer"],"summary":"Receive a stream","description":"Opens a viewer's side of the room. The first message is `{\"type\":\"hello\",\"cameraOnline\":bool,\"viewers\":n}`, then binary frames arrive as the camera sends them. `{\"type\":\"camera-offline\"}` says the camera dropped; the socket stays open, so frames resume by themselves when it comes back. When the token runs out the socket is closed with code 4001: fetch a new grant and reconnect.\n\nA room serves 16 viewers, and the grants of one credential (the API token, or website member, they were minted for) hold at most 4 of them. A viewer past either is let in and closed at once with code 4029, before any hello: retry later, backing off.","parameters":[{"name":"device_id","in":"path","required":true,"description":"The camera's device id, as registered with OpenMV Cloud.","schema":{"type":"string","pattern":"^[A-Za-z0-9_:.-]{1,128}$"}},{"name":"stream","in":"path","required":true,"description":"Which image stream on that camera. A device has one credential but any number of streams (a multi-camera board, or virtual streams an app defines); the default stream is named \"0\".","schema":{"type":"string","pattern":"^[A-Za-z0-9_.-]{1,64}$"}}],"responses":{"101":{"description":"Switching Protocols: the WebSocket is open."},"403":{"description":"The token is missing, malformed, expired, or not for this device."},"404":{"description":"No such path: the device or stream segment is malformed."},"426":{"description":"Upgrade Required: this path only answers a WebSocket upgrade."}}}},"/poll/{device_id}/{stream}":{"get":{"security":[{"cameraToken":[]}],"tags":["Camera"],"summary":"Is anyone watching?","description":"A plain HTTPS check for a camera that sleeps between frames: it takes the same camera token as the publish endpoint, so a device needs exactly one credential. Sleep while `watch` is false; open the WebSocket when it turns true.","parameters":[{"name":"device_id","in":"path","required":true,"description":"The camera's device id, as registered with OpenMV Cloud.","schema":{"type":"string","pattern":"^[A-Za-z0-9_:.-]{1,128}$"}},{"name":"stream","in":"path","required":true,"description":"Which image stream on that camera. A device has one credential but any number of streams (a multi-camera board, or virtual streams an app defines); the default stream is named \"0\".","schema":{"type":"string","pattern":"^[A-Za-z0-9_.-]{1,64}$"}}],"responses":{"200":{"description":"Whether the room has viewers right now.","content":{"application/json":{"schema":{"type":"object","required":["watch","viewers"],"properties":{"watch":{"type":"boolean","description":"True while at least one viewer is connected."},"viewers":{"type":"integer","description":"How many viewers are connected."}}},"example":{"watch":true,"viewers":2}}}},"403":{"description":"The token is missing, malformed, expired, or not for this device."},"404":{"description":"No such path: the device or stream segment is malformed."}}}},"/healthz":{"get":{"tags":["Health"],"summary":"Liveness","description":"Answers without touching a room. No token required.","responses":{"200":{"description":"The relay is up.","content":{"application/json":{"schema":{"type":"object","required":["ok","commit"],"properties":{"ok":{"type":"boolean"},"commit":{"type":"string","description":"The git commit this build was deployed from (short form); empty for a local build."}}},"example":{"ok":true,"commit":"4867f16"}}}}}}}}}