Video Streams
Real-time video analysis with WebSocket streaming.
BetaOverview
Nara Lens supports real-time video analysis through WebSocket connections. Send frames and receive analysis results with sub-100ms latency.
Connecting
JavaScript
const ws = new WebSocket('wss://api.naralens.com/v1/stream');
ws.onopen = () => {
ws.send(JSON.stringify({
type: 'auth',
api_key: process.env.NARA_API_KEY
}));
};Sending Frames
JavaScript
// Configure the perception once
ws.send(JSON.stringify({
type: 'config',
perception: 'detect:person,vehicle'
}));
// Send frames as base64
ws.send(JSON.stringify({
type: 'frame',
data: frameBase64,
timestamp: Date.now()
}));Receiving Results
JavaScript
ws.onmessage = (event) => {
const result = JSON.parse(event.data);
console.log('Frame:', result.frame_id);
console.log('Objects:', result.objects);
console.log('Latency:', result.latency_ms, 'ms');
};