Real-time control and data streaming for lens sessions via WebSocket
The Lens Events API enables real-time control and data streaming for active lens sessions via WebSocket connections. This allows you to interact with Newton models, configure input streams, and receive real-time inference results.
All event messages are JSON objects with a required type field and optional event_data field:
{ "type": "event.type", "event_data": { // Event-specific data }}
Response envelope: with the single exception of session.status (see below), every server response carries a type field suffixed with .response and wraps the result in event_data:
Response Example:Unlike other events, session.status returns the full session metadata record (the same shape as Create Lens Session), not the {type, event_data} envelope.
The response currently includes an api_key field that echoes back the caller’s real API key. Treat this field as a secret — do not log, persist, or expose it in client-side code. (Server-side scrub in progress.)
Read pending event messages from the platform, such as log messages or asynchronous inference results.
session.read only returns messages for lenses whose model_pipeline writes to the WebSocket mailbox. Lenses that use a server_sent_events_writer output processor (Activity Monitor and most cookbook lenses) route inference results to the SSE consumer endpoint instead — for those, session.read returns event_data: null even when GET /lens/sessions/metadata shows non-zero num_outputs. Inspect the lens’s model_pipeline via GET /lens/metadata to confirm which output channel it uses.
Each client should generate a unique client_id to enable parallel reading. Use a new client_id to reset message stream playback.
Description: Real-time video streaming from RTSP camerasConfiguration Parameters:
rtsp_url (string): RTSP stream URL
target_image_size (array): [height, width] in pixels
target_frame_rate_hz (float): Frames per second to process
Use Cases: Security cameras, live monitoring, real-time analysis
csv_file_reader
Description: Stream data from uploaded CSV filesConfiguration Parameters:
file_id (string): ID of uploaded CSV file
Use Cases: Time series analysis, batch data processing, historical data analysis
video_file_reader
Description: Stream a pre-recorded video file (e.g. .mp4) that was previously uploaded via the Files APIConfiguration Parameters:
file_id (string): file_id returned by the upload — typically the original filename (e.g. "my_video.mp4"), not the file_uid UUID
Use Cases: Offline analysis of recorded footage, replaying dashcam / camera archives through a vision lensSee Video File Reader for the full data-connector reference.
sensor_streamer
Description: Direct sensor data streamingConfiguration Parameters:
Configuration varies by sensor type
Use Cases: IoT sensors, accelerometers, temperature sensors
Send direct queries to Newton models with custom data payloads.
model.query is only handled by lenses whose pipeline includes a model-query processor. Lenses that wrap a streaming processor (e.g. lens_camera_processor, lens_timeseries_state_processor) expect input via input_stream.set and will time out on model.query. Responses arrive asynchronously — long-running queries return a timeout response with message: "Response timed out for query" if the model has not replied within the WebSocket read window.
Template Name: image_qa_template_taskPurpose: Generate narrative descriptions of imagesParameters:
instruction: Question or instruction for the model
focus: Specific aspect to focus on (e.g., “safety equipment”, “project status”)
max_new_tokens: Maximum response length (typically 512)
Output: Natural language description, wrapped in the WS response envelope.Example Response:
{ "type": "model.query.response", "event_data": { "result": "The image shows construction workers wearing yellow hard hats and high-visibility safety vests." }}
Timeout Response (model did not reply within the read window):
{ "type": "model.query.response", "message": "Response timed out for query"}
Template Name: image_bbox_template_taskPurpose: Detect and localize objects with bounding boxesParameters:
instruction: Object detection instruction
focus: List of objects to detect (e.g., “Input: [person,car,dog]”)
max_new_tokens: Maximum response length
Output: Structured bounding box coordinates, wrapped in the WS response envelope.Example Response: