Skip to content
中文

Live streams

A live stream connects a running broadcast to the platform. You give it a live address, or let a browser or app push to it, and it keeps turning the speech into text, describes a frame every few seconds, watches for the words you care about, and records each broadcast as a video asset in a Media library. Your business holds a handle to the stream, reads results and plays it back; the picture never passes through your servers.

Typical uses: transcribe a shopping live room as it happens and alert when the anchor says “refund” or “lowest price”; caption a training broadcast and keep a replay; write one sentence about what a camera sees every 20 seconds.

Live streams are opened organization by organization. Until they are open for yours, every path under /media/v1/streams and /media/v1/pipelines answers 404.

One broadcast, start to finish

The examples share one small helper. Save it as live.mjs and run it on Node.js 22 or later (it needs the global WebSocket).

const base = process.env.PRAXIS_API_BASE ?? "https://api.deepraxis.com";
const key = process.env.PRAXIS_API_KEY;
if (!key) throw new Error("Set PRAXIS_API_KEY");
async function media(path, method = "GET", body) {
const response = await fetch(base + "/media/v1" + path, {
method,
headers: { Authorization: `Bearer ${key}`, "Content-Type": "application/json" },
...(body === undefined ? {} : { body: JSON.stringify(body) }),
});
if (!response.ok) throw new Error(`Media HTTP ${response.status}: ${await response.text()}`);
return response.json();
}

1. Create a pipeline: what to do during the broadcast

A pipeline describes the processing that runs while a stream is live. Create it once and attach it to as many streams as you like. transcribe turns speech into text, describe_frames describes one frame every interval_s seconds, and a keyword_match in alert_rules watches the transcript for words.

const pipeline = await media("/pipelines", "POST", {
name: "live room",
elements: [
{ type: "transcribe", language: "en" },
{ type: "describe_frames", interval_s: 20 },
],
alert_rules: [{ type: "keyword_match", keywords: ["refund", "lowest price"] }],
});

2. Create a stream: pull one, or receive one

Pull: give an HLS (.m3u8), HTTP-FLV or RTMP address and Praxis pulls it. The stream starts pulling as soon as it is created; the create answer shows idle, and a read a few seconds later shows waiting or active. While the source is not live yet the stream is waiting, which is neither a failure nor a charge, and it becomes active by itself once the source goes live.

const stream = await media("/streams", "POST", {
input: { kind: "pull", url: "https://live.example.com/room/index.m3u8" },
pipeline_id: pipeline.id,
recording: { mode: "automatic", rendition: "source" },
playback: { enabled: true },
});

Push: input: { kind: "push" }. The response carries push.url, the address to push to with its token already in it. It appears only in that response; get a new one with reset-token. In a browser, push with the Kit StreamPublisher (see “Push from a browser” below).

With recording.mode set to automatic every broadcast is recorded as one video asset. With playback.enabled set to true the live broadcast can be watched in a browser. reconnect_window_s is how long a dropped source may take to come back and still count as the same broadcast.

3. Read the results

The same event log can be read three ways.

In pages, with no connection to keep open. after is the highest seq you have seen; pass 0 to read from the start:

let after = 0;
const page = await media(`/streams/${stream.id}/events?after=${after}&limit=100`);
for (const event of page.data) {
if (event.kind === "transcript.final") console.log(event.offset_ms, event.data.text);
}
after = page.next_after;

Subscribe socket, for live delivery. Mint a subscribe token, then append after to the address. After a disconnect, reconnect with the last seq you saw and the missed events are sent first. An event can arrive twice, so de-duplicate on the event id.

const sub = await media(`/streams/${stream.id}/subscribe-token`, "POST");
const socket = new WebSocket(`${sub.url}&after=${after}`);
socket.onmessage = ({ data }) => {
const event = JSON.parse(data);
if (event.kind === "transcript.final") console.log(event.data.text);
};

Webhook, delivered to your server. Add { type: "webhook", url } to the pipeline’s elements. The signing secret whsec_… appears only in the response that creates or updates the pipeline, so keep it. Each delivery’s body is one event as JSON, with three headers: webhook-id (the event id, unchanged on a retry), webhook-timestamp and webhook-signature. The signature follows Standard Webhooks: HMAC-SHA256 over <webhook-id>.<webhook-timestamp>.<body>, sent as v1, followed by base64. Delivery is at least once and in event order, and a 2xx answer counts as received; de-duplicate on webhook-id.

The kinds of event:

kindMeaning
stream.waiting, stream.connected, stream.active, stream.disconnected, stream.idleThe stream’s life cycle
transcript.partial, transcript.finalTranscription. data.text is the text; the partials and the final of one sentence share a data.sentence_id; data.start_ms and data.end_ms are where the sentence sits in the recording; data.broadcast_id names the broadcast
frame.describedA description of one frame, in data.text
pipeline.describe_failedA frame description failed; data.step and data.message say where
output.statusA re-broadcast target changed status
alertAn alert rule matched; data.rule_id names the rule, data.matched lists the words and data.source_event_ids points at the transcript that triggered it, whose offset_ms the alert shares
recording.ready, recording.failedA broadcast became an asset (data.asset_id), or did not (data.reason)
pipeline.unsupported_audioThis audio cannot be transcribed yet; data.codec names the encoding

The event log is kept for at least 24 hours.

4. The recording: one asset per broadcast

When recording.ready arrives, that broadcast is an asset in a Media library (a video unless you asked for audio only). Name the library with recording.library_id when you create the stream, then find every recording of a stream (library.id below is that library’s id):

const recordings = await media(`/libraries/${library.id}/assets?live_stream_id=${stream.id}`);

The asset’s provenance names the stream and when that broadcast started and ended.

When you only need the sound, create the stream with recording.rendition: "audio_only": every broadcast is recorded as one m4a audio asset with no picture, a small fraction of the size of the same broadcast as video. For example, to keep each day’s whole broadcast and transcribe it by time afterwards:

recording: { mode: "automatic", rendition: "audio_only" },
max_continuous_duration_s: 43200, // one broadcast runs at most 12 hours

5. Playback

The live broadcast. Your server trades its API key for a playback address and gives that to the page, so the key never reaches the browser:

const playback = await media(`/streams/${stream.id}/playback-token`, "POST"); // { url, expires_at }

The address is valid for one hour and needs no API key. It plays the newest segments of the broadcast in progress, and the playlist ends with EXT-X-ENDLIST when the stream ends. The stream needs playback.enabled (or automatic recording) first, otherwise the answer is 409; turning it on during a broadcast takes effect from the next one.

In a page, use the Kit player, with captions:

import { LiveStreamPlayer } from "@deepraxis/kit-react";
// /my-backend/live calls playback-token and subscribe-token on your server and returns { playbackUrl, subscribeUrl }
<LiveStreamPlayer source={() => fetch("/my-backend/live").then(r => r.json())} autoPlay muted />

Without React, use the custom element <praxis-live-stream playback-url="…" subscribe-url="…"> from https://cdn.deepraxis.com/v1/praxis-video.js. Captions come from the transcript on the subscribe socket and show when the picture reaches that sentence, so a viewer behind the live edge sees captions equally late, never before the picture.

A recording. The player takes a recording’s play address (recording-url). Your server reads the asset’s transcript from Media and passes it as cues ([{ startMs, endMs, text }]) to LiveStreamPlayer, so the browser never touches an API key.

6. Usage and health

A stream carries two read-only fields:

  • health: while it is live, the bitrate (bitrate_kbps), latency (latency_ms), dropped segments (dropped_segments), reconnects (reconnects) and the time of the newest segment (last_segment_at); null when it is not live.
  • usage: broadcast (the broadcast in progress, null when none) and total (everything the stream has used), each with stream_seconds, processor_seconds and recorded_bytes.

7. Stop and clean up

POST /media/v1/streams/{stream_id}/disable stops a stream: the broadcast in progress is closed out and the stream gives back its live slot. DELETE /media/v1/streams/{stream_id} removes it, which works only while it is idle or disabled; the recordings it made stay as assets. A pipeline can be deleted once no stream names it.

Push from a browser

The Kit StreamPublisher pushes a browser’s camera and microphone to a push stream. The audio is transcribed, and the picture goes into the recording and playback.

import { StreamPublisher } from "@deepraxis/kit/stream";
// Your server created the push stream and hands push.url to the page
const publisher = new StreamPublisher({ url: pushUrl });
const media = await navigator.mediaDevices.getUserMedia({ audio: true, video: true });
await publisher.start(media);
// ...when the broadcast ends
await publisher.stop();

The stream takes MP4 only, so the browser must be able to record MP4; otherwise start throws a StreamPublisherError. Audio-only publishing is not affected.

Time

An event carries two times:

  • offset_ms: where the event sits in that broadcast’s recording, counted from its start. Use it to line events up with the recording.
  • at: the wall clock. Use it to line events up with outside data, such as a shop’s sales per minute. at_source says where it comes from: the source’s own clock when its HLS carries PROGRAM-DATE-TIME (program_date_time), otherwise the time Praxis received it (received). The first events of a pulled stream carry the time of the segment they came from, which can be a little earlier than the stream’s created_at.

The at of recording.ready and recording.failed is when the result was reached, not when the stream stopped: a long broadcast is assembled after it ends and its result can arrive tens of minutes later. Their offset_ms is the end of the broadcast. When a broadcast gets recording.failed and then, after it was assembled again, recording.ready, the recording.ready is the one that counts.

Limits

  • An organization can have 5 streams live at once by default. A stream that would exceed it stays as it was, and its log records stream.disconnected with data.reason quota_exceeded.
  • One broadcast runs at most 12 hours (max_continuous_duration_s up to 43200); a source still live then starts the next broadcast.
  • interval_s of describe_frames is a lower bound, not a promise. One description (fetch the segment, cut a keyframe, call the image model) takes about 12 seconds at the median, and when it cannot keep up the frames in between are skipped, not queued. Set interval_s to 15 seconds or more.
  • Transcription takes AAC audio only for now. Opus and mp3 are not supported yet; the stream carries on and its log shows pipeline.unsupported_audio.
  • fMP4 cannot be re-broadcast (simulcast outputs).
  • A re-broadcast target cannot be a service on Cloudflare’s network, Cloudflare Stream included: the platform cannot connect to those addresses, so the output goes straight to errored with OUTPUT_TARGET_UNREACHABLE_FROM_PLATFORM and is not retried.
  • Pushing straight from OBS and similar software is coming soon; for now browsers and apps use StreamPublisher, and any other source is pulled.

Price

A stream is metered in three quantities: live time, processing time and recorded size. It is currently free, and the metering is recorded as usual; you see the quantities in the stream’s usage field.

API reference →