# Realtime

Mint a short-lived token so a browser can receive live updates over WebSocket.

Paths start at `$ACTIVQC_BASE_URL`, and every call sends `Authorization: Bearer $ACTIVQC_KEY`. Errors use the [error envelope](https://activqc.wavbee.com/docs/errors.md). [All endpoints](https://activqc.wavbee.com/docs/api-reference.md).

## POST /v1/realtime/tokens

Mint a short-lived Action Cable token.

**Auth:** a secret key, `Authorization: Bearer $ACTIVQC_KEY`.

#### Request body

`application/json`.

Mint a short-lived (10 minutes), single-use WebSocket token (`wqc_ct_…`) for live updates over Action Cable. Omit `draft_id` and `run_id` for a tenant-scoped token, or pass either to narrow the token to that release draft or QC run.

| Field | Type | Description |
|---|---|---|
| `draft_id` | string | Optional release draft public id (`rd_…`) to narrow the token's subscription scope. Example `rd_7fK2aBcDeFgHiJkLmNoPqRsT`. |
| `run_id` | integer | Optional QC run id to narrow the token's subscription scope. Example `42`. |

#### Example request

```bash
curl -s -X POST "$ACTIVQC_BASE_URL/v1/realtime/tokens" \
  -H "Authorization: Bearer $ACTIVQC_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "draft_id": "rd_7fK2aBcDeFgHiJkLmNoPqRsT",
  "run_id": 42
}'
```

#### Responses

| Status | Meaning |
|---|---|
| `201` | Realtime token minted. |
| `401` | Missing or unknown API key. [Error envelope](https://activqc.wavbee.com/docs/errors.md). |
| `404` | Draft_id or run_id not found or owned by another tenant. [Error envelope](https://activqc.wavbee.com/docs/errors.md). |

#### Response `201`

| Field | Type | Description |
|---|---|---|
| `object` | string | **Required.** Always `realtime.token`. |
| `token` | string | **Required.** Single-use token valid for 10 minutes. Present via `Sec-WebSocket-Protocol` or `?token=`. Example `wqc_ct_9f3c...`. |
| `expires_at` | string (date-time) | **Required.** |
| `url` | string | **Required.** Example `wss://YOUR-ACTIVQC-HOST/cable`. |
| `scope` | object | **Required.** |
| `scope.draft_id` | string or null | **Required.** Example `rd_7fK2aBcDeFgHiJkLmNoPqRsT`. |
| `scope.run_id` | integer or null | **Required.** Example `42`. |

```json
{
  "object": "realtime.token",
  "token": "wqc_ct_9f3c...",
  "expires_at": "2026-11-24T10:00:00Z",
  "url": "wss://YOUR-ACTIVQC-HOST/cable",
  "scope": {
    "draft_id": "rd_7fK2aBcDeFgHiJkLmNoPqRsT",
    "run_id": 42
  }
}
```

