API v2 and SDK
API v2.
Rooms, video streams and real-time data, under /api/v2. Send Authorization: Bearer with either kind of key: an API key acts for your organisation within its scopes, a stream key acts only inside its room. The SDK wraps every call here. v1 is unchanged and keeps working.
Conventions
JSON in and out. Errors are{ error: { code, message } }. A key over its rate limit gets 429 with Retry-After. Browsers may call v2 from any origin: keys travel in the header, never in cookies.Room object
{
"id": "V1StGXR8_Z5jdHi6B-myT",
"name": "Support session 42",
"status": "live", // offline | live | ended
"hls": "main", // off | main | all: which video streams HLS records
"hlsPlaybackUrl": "https://…/live.m3u8",
"videoStreams": [
{
"name": "main",
"status": "live",
"identity": "host-laptop",
"recording": true,
"hlsPlaybackUrl": "https://…/live.m3u8",
"connectedAt": "…",
"disconnectedAt": null
}
],
"estop": null, // or { "at": "…", "reason": "…" } while latched
"createdAt": "…",
"updatedAt": "…"
}A room is the same record as a v1 stream, so v1 and v2 see the same rooms. Each connection that may publish video is one video stream, named when it connects.
Rooms
| Endpoint | Scope |
|---|---|
| GET /v2/rooms | rooms:read |
| POST /v2/rooms { name, hls? } | rooms:write |
| GET /v2/rooms/:id | rooms:read, or a stream key for that room |
| PATCH /v2/rooms/:id { name?, hls? } | rooms:write |
| DELETE /v2/rooms/:id | rooms:write |
| GET /v2/rooms/:id/sessions | rooms:read, or a stream key for that room |
A new hls value applies at once, and sending the current one again restarts any recording it covers that isn't running. Sessions are the room's live periods, newest first: one opens when the first video stream connects and ends when the room closes.
Who's connected
| Endpoint | Scope |
|---|---|
| GET /v2/rooms/:id/participants | rooms:read, or a stream key for that room |
| GET /v2/rooms/:id/participants/:identity | rooms:read, or a stream key for that room |
| PATCH /v2/rooms/:id/participants/:identity { can } | rooms:write, plus rooms:connect to add a capability |
| DELETE /v2/rooms/:id/participants/:identity | rooms:write |
{
"identity": "driver-2",
"name": "Sam",
"can": ["video.receive", "audio.receive", "data.publish"],
"video": null, // its video stream's name, when it publishes one
"keyId": "…", // the stream key it connected with, or null
"joinedAt": "…"
}PATCH changes what a live connection may do, without it reconnecting: turn receiving, audio.publish and data.publish on or off. Use it to let one connection send commands at a time, to mute someone, or to stop sending someone video. video.publish stays as the connection was granted, and only connections made through v2 can change. While the room is e-stopped the change is kept and data stays off until it's cleared. A change lasts for the connection: reconnecting with the same key gets the key's capabilities again, so mint keys with the least each app needs. DELETE disconnects someone; revoke their key to keep them out.
Data from your server
POST /v2/rooms/:id/data sends a data message into a room without connecting. Scope: rooms:connect. Receivers get it on its topic with no sender. Refused with 409 estopped while the room is e-stopped; sent is false when the room isn't open.
| Body | Type | Description |
|---|---|---|
| topicrequired | string | What receivers listen on. |
| text | string | The payload as text. Send text or base64. |
| base64 | string | The payload as base64 bytes. Up to 15 KiB. |
| to | string[] | Only these identities receive it. Default: everyone. |
| reliable | boolean | Ordered and retried. Default: true. |
E-stop
| Endpoint | Scope |
|---|---|
| POST /v2/rooms/:id/estop { reason? } | rooms:write or controller:write |
| DELETE /v2/rooms/:id/estop | rooms:write or controller:write |
Latching the e-stop stops every connection sending data, including connections that join while it's latched and messages sent from your server. Only v1 robot connections keep sending, for telemetry. Connections hear it at once (the SDK's estop event). Clearing it gives every v2 connection back the data permission it was granted; a v1 controller stays revoked until one is assigned. Both are idempotent, and the room object shows the latch.
Stream keys
| Endpoint | Scope |
|---|---|
| POST /v2/rooms/:id/keys | keys:write |
| GET /v2/rooms/:id/keys | keys:read |
| GET /v2/keys/:id | keys:read |
| DELETE /v2/keys/:id | keys:write |
| POST body | Type | Description |
|---|---|---|
| canrequired | string[] | What a connection may do: video.publish, video.receive, audio.publish, audio.receive, data.publish. |
| identity | string | Every connection made with the key gets this identity. Omit it and each connection gets a made-up guest identity. |
| label | string | To tell keys apart in a list. |
| expiresIn | integer | Seconds until the key stops working, 60 to 31536000. Omit for no expiry. |
The response carries the key once, as streamKey. Revoking a key disconnects everyone using it and refuses it from then on; the response says how many were disconnected.
Connect
POST /v2/rooms/:id/connect returns what an app needs to join: the transport to use and its credentials. An API key needs rooms:connect and works for any room of its organisation; a stream key works for its own room.
| Body | Type | Description |
|---|---|---|
| identity | string | Required with an API key. A stream key connects as its fixed identity, or as a made-up guest identity when it has none; sending a different identity fails with identity_fixed or identity_not_allowed. |
| can | string[] | What this connection may do. With an API key: video.receive, audio.receive and data.publish unless you ask for more; ask for video.publish or audio.publish to publish. With a stream key: everything the key allows. |
| video | string | The name its video is published under. Default: main. A room takes up to eight. |
| name | string | Display name other participants see. |
{
"transport": { "kind": "livekit", "url": "wss://…", "token": "…" },
"room": { "id": "…" },
"identity": "agent-7",
"can": ["video.receive", "audio.receive", "data.publish"],
"video": null,
"expiresAt": "…"
}Join before expiresAt, which is never later than the stream key's own expiry; once joined, the connection lasts until it ends. While the room is e-stopped, connections can't send data until the e-stop is cleared. The SDK picks its adapter by transport.kind, so the transport can change without changing apps.
The media server enforces publishing per kind: camera, microphone and data. Receiving is one permission per connection, so video.receive and audio.receive choose what a connection takes; a client outside the SDK holding either could ask for both. A connection that publishes video and audio is one video stream, and HLS records its sound with it.
Your key
GET /v2/key returns the key you're calling with and what it can do. Any valid key may read itself.
// an API key
{ "kind": "api", "orgId": "…", "keyId": "…", "name": "Backend",
"scopes": ["rooms:read", "rooms:write", "…"], "expiresAt": null }
// a stream key
{ "kind": "stream", "orgId": "…", "roomId": "…", "keyId": "…",
"identity": "kiosk-1", "can": ["video.receive"], "expiresAt": "…" }Organisation
| Endpoint | Scope |
|---|---|
| GET /v2/org | org:read |
| PATCH /v2/org { name?, slug? } | org:write |
| GET /v2/org/keys | org:read |
| GET /v2/org/keys/:id | org:read |
| POST /v2/org/keys { name, permissions, expiresIn? } | org:write |
| DELETE /v2/org/keys/:id | org:write |
| GET /v2/org/webhooks | webhooks:manage |
| POST /v2/org/webhooks { url } | webhooks:manage |
| PATCH /v2/org/webhooks/:id { enabled } | webhooks:manage |
| POST /v2/org/webhooks/:id/test | webhooks:manage |
| DELETE /v2/org/webhooks/:id | webhooks:manage |
A key can't create an API key with a scope it doesn't hold itself. New keys return their secret once, as apiKey. expiresIn is in seconds, from a day to a year. Nothing a key creates outlives it: a key that expires caps the expiry of the API keys and stream keys it makes. A paused webhook endpoint keeps its secret and misses events until it's resumed. The test sends a signed webhook.test event and returns { ok, status, error }.
Members
| Endpoint | Scope |
|---|---|
| GET /v2/org/members | org:read |
| PATCH /v2/org/members/:userId { role } | every scope |
| DELETE /v2/org/members/:userId | every scope |
| GET /v2/org/invitations | org:read |
| POST /v2/org/invitations { email, role? } | every scope |
| DELETE /v2/org/invitations/:id | every scope |
An admin can do anything a key can, so managing members takes a key that holds every scope. Roles are admin and member; owners are managed in the dashboard. An invitation is accepted at its acceptUrl within 48 hours, signed in with the invited address. When emailed is false, send the link yourself. An organisation can have 100 invitations waiting.
Scopes
| Scope | Allows |
|---|---|
| rooms:read | List and read rooms, who's connected and sessions. Also granted by streams:read. |
| rooms:write | Create, update and delete rooms, latch and clear the e-stop, change and disconnect connections. streams:write grants it too, except the e-stop and changing connections. |
| rooms:connect | Connect to any room of the organisation, and send it data from a server. |
| keys:read | List and read stream keys. |
| keys:write | Mint and revoke stream keys. |
| org:read | Read the organisation, its API keys, members and invitations. |
| org:write | Rename the organisation; create and delete API keys holding no more than the calling key. |
| webhooks:manage | Manage, pause and test webhook endpoints. |