Skip to main content

Stream

POST 

/workstations/:workstation_id/recorder/stream

Get a real-time stream of the Workstation's audio and video activity. This endpoint returns a streaming URL that can be used to establish a connection with the Workstation's audio/video feed using HLS (HTTP Live Streaming) or WebRTC (coming soon).

HLS.js

// Using HLS.js to stream audio/video from the Workstation
const id = 'HvcqZjmeoPtP';
const url = `https://api.agentstation.ai/v1/workstations/${id}/recorder/stream`;

// Get stream URL from AgentStation API
const response = await fetch(url, {
method: 'POST',
headers: {
'Authorization': 'Bearer <your_token>'
},
body: JSON.stringify({
type: 'video', // or 'audio'
protocol: 'hls'
})
});
const stream = await response.json();
// stream.url example: https://stream.agentstation.ai/v1/hls/video/cxBMzXSFUSXf

// Initialize HLS.js
const video = document.getElementById('video');
const hls = new Hls({
debug: false,
enableWorker: true,
lowLatencyMode: true,
backBufferLength: 90,
// Optimize for low latency
maxBufferSize: 2 * 1000 * 1000, // 2MB
maxBufferLength: 4, // 4 seconds
maxMaxBufferLength: 10, // 10 seconds
// Optimize for quality
startLevel: -1, // Auto quality selection
capLevelToPlayerSize: true, // Adapt quality to player size
// Optimize for reliability
manifestLoadingTimeOut: 10000, // 10 seconds
manifestLoadingMaxRetry: 3,
levelLoadingTimeOut: 10000, // 10 seconds
levelLoadingMaxRetry: 3
});

// Bind HLS to video element
hls.loadSource(stream.url);
hls.attachMedia(video);

// Handle HLS events
hls.on(Hls.Events.MEDIA_ATTACHED, () => {
console.log('HLS attached to video element');
video.play();
});

hls.on(Hls.Events.MANIFEST_PARSED, (event, data) => {
console.log('Manifest loaded, found ' + data.levels.length + ' quality levels');
});

hls.on(Hls.Events.ERROR, (event, data) => {
if (data.fatal) {
switch (data.type) {
case Hls.ErrorTypes.NETWORK_ERROR:
console.log('Fatal network error, trying to recover...');
hls.startLoad();
break;
case Hls.ErrorTypes.MEDIA_ERROR:
console.log('Fatal media error, trying to recover...');
hls.recoverMediaError();
break;
default:
console.log('Fatal error, destroying HLS instance');
hls.destroy();
break;
}
}
});

HTML5 Video Player

<!-- Basic HTML5 video player -->
<video id="video" controls playsinline>
<source src="https://stream.agentstation.ai/v1/hls/video/cxBMzXSFUSXf" type="application/x-mpegURL">
Your browser does not support HLS video playback.
</video>

Stream Specifications

HLS Protocol

  • Video Stream:
    • Codec: H.264/AVC
    • Resolution: 1280x720 (720p)
    • Framerate: 24 fps
    • Bitrate: Variable (500 Kbps - 2 Mbps)
    • Keyframe Interval: 48 frames (2 seconds)
    • Profile: High
    • Level: 4.1
  • Audio Stream:
    • Codec: AAC-LC
    • Channels: 2 (Stereo)
    • Sample Rate: 48 kHz
    • Bitrate: 128 Kbps
  • Streaming Details:
    • Segment Duration: 2 seconds
    • Playlist Window: 30 segments (60 seconds)
    • Latency: ~4-6 seconds
    • Seeking: Frame-accurate throughout timeline
    • Adaptive Bitrate: Yes (automatic quality switching)

WebRTC Protocol (Coming Soon)

  • Ultra-low latency (~100-300ms)
  • Peer-to-peer connection
  • Adaptive quality based on network conditions

Notes

  • Recording must be started via /recorder/start before this endpoint will return a valid stream URL
  • You can check the current recording status using the /recorder endpoint
  • The stream URL contains a secure token that authenticates the connection

Request

Responses

Stream-Recorder action successful