Skip to main content
Complete working examples for common use cases using the Lens Events API.
Prerequisites: Set your API key as an environment variable:

CSV File Streaming Example

Stream data from a CSV file through a lens for time-series analysis.

Step 1: Download Sample Data

Step 2: Upload CSV File

Step 3: Stream CSV Through Lens

What you should expect:
  • Creating lens session… then Connecting to WebSocket… → both succeed in under 1s.
  • Validating session…Session is valid! returns {"type": "session.validate.response", "event_data": {"is_valid": true, "error_messages": []}}.
  • Configuring CSV stream…Stream configured: {'type': 'input_stream.set.response', 'event_data': {'is_valid': true, 'error_messages': []}}.
  • Reading streaming results… → the content depends entirely on the lens you connect the stream to. A lens whose pipeline matches the CSV’s schema (column names, sampling rate) will emit inference.result messages over time; an incompatible lens will return {"type": "session.read.response", "event_data": null} on each poll. Confirm the lens’s expected schema from GET /lens/metadata before running.

RTSP Camera Streaming Example

Stream real-time video from an RTSP camera for live analysis.
What you should expect:
  • Session creation, WebSocket connection, and session.validate all succeed (same envelope shapes as the CSV example above).
  • RTSP stream configured: {'type': 'input_stream.set.response', 'event_data': {'is_valid': true, ...}}.
  • inference.result payloads arrive on session.read polls — typical content is a short natural-language description of the latest frame batch (no confidence or processing_time_ms fields are guaranteed by the model). Frequency depends on the lens’s camera_buffer_size and the target_frame_rate_hz you configured on the stream.
  • An unreachable RTSP URL surfaces as an error message in subsequent session.read polls rather than a synchronous error on input_stream.set.

Direct Image Analysis Example

Send individual images for immediate analysis without setting up streams.
model.query only works against lenses whose pipeline includes a model-query processor (i.e. not the Activity Monitor — which uses lens_camera_processor and expects camera input). If your model.query returns {"type": "model.query.response", "message": "Response timed out for query"}, the lens is not configured to handle direct queries. Register a model-query lens first via POST /lens/register or use a streaming approach with input_stream.set instead.

Repository and Additional Examples

Python Client Examples

Complete example repository with more use cases

WebSocket Events API

Detailed WebSocket event documentation

File Upload API

Upload files for CSV streaming

Troubleshooting

Common issues and solutions

Common Use Cases

Application: Real-time security camera analysisSetup: RTSP camera stream with person/vehicle detectionFocus Examples:
  • “Detect unauthorized personnel”
  • “Monitor for safety violations”
  • “Count people in restricted areas”