The OZ Data SDK is a TypeScript-first client for consuming Visual Intelligence streams. It handles authentication, connection management, event subscriptions, and schema validation, so you can focus on what you do with the data.
Install the SDK from npm. Requires Node.js 18+ or any runtime with Web Streams API support.
npm install @oz/data-sdkCreate a single OZClient instance at process start. The client manages token refresh, reconnection, and connection pooling internally. Reuse it across all subscriptions.
import { OZClient } from '@oz/data-sdk';
const client = new OZClient({
clientId: process.env.OZ_CLIENT_ID!,
clientSecret: process.env.OZ_CLIENT_SECRET!,
});
// Connect to a specific venue
await client.connect({
venue: 'venue-nk9',
quality: 'production',
});
console.log('Connected:', client.status);| Name | Type | Required | Description |
|---|---|---|---|
| clientId | string | required | Your OZ application client ID |
| clientSecret | string | required | Your OZ application client secret |
| baseUrl | string | default: https://api.oz-global.com/v1 | API base URL override |
| timeout | number | default: 30000 | Request timeout in milliseconds |
| maxRetries | number | default: 3 | Max automatic retry attempts on transient errors |
After connecting, query available scenes and open a session to start receiving events. Sessions are scoped to a single scene and maintain ordering guarantees.
// List available scenes
const scenes = await client.venues.listScenes('venue-nk9');
// Open a session to the first active scene
const session = await client.sessions.create({
sceneId: scenes[0].id,
mode: 'realtime',
});
console.log('Session opened:', session.id);Subscribe to scene events using typed event handlers. Events arrive in deterministic order with idempotent IDs, so you can safely replay and deduplicate.
import type { SceneEvent } from '@oz/data-sdk';
client.on('scene.event', (event: SceneEvent) => {
switch (event.type) {
case 'object.moved':
console.log(`Object ${event.payload.object_id} moved to`, event.payload.to);
break;
case 'zone.enter':
console.log(`Object entered zone ${event.payload.zone_id}`);
break;
case 'zone.exit':
console.log(`Object exited zone ${event.payload.zone_id}`);
break;
}
});
client.on('error', (err) => {
console.error('Stream error:', err.code, err.message);
});The SDK includes runtime schema validators for all event types. Enable strict mode to throw on unexpected payload shapes. This is useful during development and CI.
import { OZClient, StrictValidator } from '@oz/data-sdk';
const client = new OZClient({
clientId: process.env.OZ_CLIENT_ID!,
clientSecret: process.env.OZ_CLIENT_SECRET!,
validator: new StrictValidator(),
});
// In strict mode, unknown event types throw a SchemaError
// instead of being silently ignored.
client.on('schema.error', (err) => {
console.error('Unexpected event shape:', err.eventType, err.details);
});The SDK ships full TypeScript declarations. Key types you'll work with:
interface OZClientOptions {
clientId: string;
clientSecret: string;
baseUrl?: string;
timeout?: number;
maxRetries?: number;
validator?: EventValidator;
}
interface SceneEvent {
event_id: string;
type: 'object.moved' | 'zone.enter' | 'zone.exit' | 'incident';
timestamp: string;
scene_id: string;
payload: Record<string, unknown>;
}
interface Session {
id: string;
scene_id: string;
mode: 'realtime' | 'historical';
status: 'active' | 'closed';
created_at: string;
}The SDK surfaces errors as typed OZError instances with a machine-readable code, message, and request_id. Network errors trigger automatic retries (up to maxRetries). Subscribe to the error event for centralized handling.
import { OZError } from '@oz/data-sdk';
client.on('error', (err: OZError) => {
logger.error({
code: err.code,
message: err.message,
requestId: err.requestId,
});
if (err.code === 'connection_lost') {
// SDK reconnects automatically, but you can
// update your UI or health check status here.
healthCheck.setDegraded('oz-connection');
}
});Need help with your integration? Our engineering team is available to pair on your first deployment.