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.Documentation Index
Fetch the complete documentation index at: https://docs.archetypeai.app/llms.txt
Use this file to discover all available pages before exploring further.
Connection Setup
1. Create a Lens Session
First, create a lens session using the REST API:session_endpoint for WebSocket connection:
2. Connect to WebSocket
For JavaScript, use the
Sec-WebSocket-Protocol header to pass authentication and protocol version.Event Message Format
All event messages are JSON objects with a requiredtype field and optional event_data field:
Session Events
session.status
Query the current status of the active session.session.validate
Run validation checks on the current session, including health checks and model connectivity.session.read
Read pending event messages from the platform, such as log messages or asynchronous inference results.Each client should generate a unique
client_id to enable parallel reading. Use a new client_id to reset message stream playback.session.destroy
Destroy the active session directly via the control stream.Input Stream Configuration
input_stream.set
Configure input data streams to automatically feed data through the lens.RTSP Video Stream
Connect a real-time video camera using RTSP protocol:CSV File Reader
Connect a CSV file for data streaming:Available Input Stream Types
rtsp_video_streamer
rtsp_video_streamer
Description: Real-time video streaming from RTSP camerasConfiguration Parameters:
rtsp_url(string): RTSP stream URLtarget_image_size(array): [height, width] in pixelstarget_frame_rate_hz(float): Frames per second to process
csv_file_reader
csv_file_reader
Description: Stream data from uploaded CSV filesConfiguration Parameters:
file_id(string): ID of uploaded CSV file
sensor_streamer
sensor_streamer
Description: Direct sensor data streamingConfiguration Parameters:
- Configuration varies by sensor type
Direct Model Queries
model.query
Send direct queries to Newton models with custom data payloads.Image QA Example
Object Detection Example
Newton Model Templates
Available Templates
- Image QA Template
- Object Detection Template
Template Name:
image_qa_template_taskPurpose: Generate narrative descriptions of imagesParameters:instruction: Question or instruction for the modelfocus: Specific aspect to focus on (e.g., “safety equipment”, “project status”)max_new_tokens: Maximum response length (typically 512)
Error Handling
Handle WebSocket errors and connection issues:Best Practices
Connection Management
Connection Management
- Always authenticate WebSocket connections with your API key
- Implement connection retry logic with exponential backoff
- Set appropriate timeouts for requests (30 seconds recommended)
- Close connections properly to free resources
Event Handling
Event Handling
- Use unique
client_idfor each client to enable parallel processing - Handle asynchronous events properly with
session.read - Implement error handling for malformed responses
- Log events for debugging and monitoring
Performance Optimization
Performance Optimization
- Use appropriate image sizes for video streams (360x640 recommended)
- Set reasonable frame rates (0.2 Hz for most use cases)
- Monitor processing times and adjust accordingly
- Batch similar queries when possible
Next Steps
Examples Repository
Explore complete working examples
Session Management
Monitor and manage active sessions
File Upload API
Upload files for CSV streaming
Troubleshooting
Solve common WebSocket issues