NeccessoryNeccessory
Web SDK

Configuration

Every option of createMeasurement(), delivery and aux settings, camera behavior and the package's other exports.

createMeasurement(options) takes one options object. mode selects the processing mode, and the other options depend on it.

import { createMeasurement } from '@neccessory/web-sdk';

const m = createMeasurement({
  videoEl: document.getElementById('camera'),
  previewEl: document.getElementById('preview'),
  overlayEl: document.getElementById('overlay'),
  mode: 'cloud',
  session,
  delivery: 'auto',
});

Common options

OptionTypeDefaultDescription
videoElHTMLVideoElement—Required. The video element the SDK attaches the camera to.
previewElHTMLCanvasElement | HTMLCanvasElement[]—Canvas, or several, where the SDK draws the camera picture.
overlayElHTMLCanvasElement | HTMLCanvasElement[]—Canvas, or several, where the SDK draws a frame around the detected face. Place it over the preview.
mode'on-device' | 'cloud''on-device'Processing mode. Set 'cloud' explicitly: without it, the SDK runs on-device and ignores the cloud options.

On-device options

OptionTypeDefaultDescription
modelGrantstring—Required. Grant from POST /sdk/v1/models/grant, minted by your backend. Valid for 15 minutes.

On-device mode also takes credentials through m.init():

FieldTypeDescription
keyIdstringYour key ID. The SDK adds it to the result.
secretstringOptional. Needed only for m.submit() from the browser. Never put it on a public page.

Cloud options

OptionTypeDefaultDescription
sessionCloudSession—The whole data object from POST /sdk/v1/cloud/sessions. The usual way to pass a session.
sessionTokenstringsession.sessionTokenOverrides the session token.
sessionIdstringsession.sessionIdOverrides the session ID.
wsUrlstringsession.wsUrlOverrides the live connection address. Without it, only delivery: 'batch' works.
delivery'stream' | 'batch' | 'auto''auto'How measurement data reaches Neccessory cloud — see below.
maxDurationSecnumbersession.maxDurationSec, else 60The measurement ends automatically after this many seconds and the result arrives. Set the duration with durationSec when you create the session.
aux'stream' | 'buffer' | 'off'automaticAdditional face data for the emotion and gaze metric sets — see below.

Advanced options

Most integrations never set these.

OptionModeDefaultDescription
assetOriginbothhttps://neccessory.comHost of the SDK runtime files. On localhost, 127.0.0.1 and *.localhost the default is your page's own origin — set https://neccessory.com there. Otherwise change it only if Neccessory gave you a dedicated host.
apiOrigincloudhttps://neccessory.comAPI host the SDK uploads to. Change it only if Neccessory gave you a dedicated host.
mediapipeBasecloudhttps://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.21/Base URL of the face-tracking library. Set it to host the library yourself when cdn.jsdelivr.net is blocked. Must end with /; the SDK loads +esm and wasm/ relative to it.
modelBasePathcloud{assetOrigin}/mediapipe/Where the face-tracking model files are served from. Change it only when you host these files yourself — ask support@neccessory.com for them.

Delivery

delivery controls how measurement data reaches Neccessory cloud and what happens when the connection drops.

ValueLive updatesIf the connection drops
'auto' (default)YesThe SDK keeps a local copy of the measurement data, uploads it and still returns a result. onDeliveryFallback fires, live updates stop, and onStage reports uploading, then processing.
'stream'YesThe measurement ends with stream_interrupted.
'batch'NoNot applicable. The SDK uploads the data when the measurement ends, and the result arrives after processing.

Keep 'auto' unless you have a reason to change it:

  • Use 'batch' with test keys — their sessions have no live connection — and on networks that block WebSockets.
  • Use 'stream' when you prefer an error to a late result.

The measurement also ends early when the tab is hidden. With 'stream' it fails with stream_interrupted; with 'auto' and 'batch' the SDK uploads what it captured and returns a result.

Additional face data

aux controls the additional face data that the emotion and gaze metric sets need.

ValueBehavior
'stream'Sent during the measurement. Default when the session includes emotion or gaze and delivery is not 'batch'.
'buffer'Kept on the device and sent only if the measurement finishes by upload. Default otherwise.
'off'Never sent. Emotion, gaze and attention come back as null.

The default matches your session. Set 'off' if you never use these metrics and want to send less data.

The camera

  • start() opens the front camera — up to 1280×720 at 30 fps — and attaches it to videoEl. The SDK sets playsinline, muted and autoplay on the element.
  • stop() releases the camera. With the React hook, so does unmounting the component.
  • You cannot pass your own MediaStream or frames. The SDK controls the capture because frame rate and resolution determine signal quality.
  • To use the video yourself, read it from videoEl — for example, videoEl.srcObject — between start() and stop().

To show the camera, display either videoEl or the preview canvas. When you show the canvas, keep the video element in the page but visually hidden — for example, 1×1 px with opacity: 0. The SDK sizes the canvases to the camera resolution; scale them with CSS. Nothing is mirrored: for a selfie view, apply transform: scaleX(-1) to every element you show.

Other exports

ExportDescription
prefetchMeasurement(options?: { assetOrigin?: string }): voidOn-device. Starts downloading the SDK runtime before the user presses Start. Call it once, early.
signAndSubmit({ keyId, secret, result, endpoint?, includeAdvanced? }): Promise<MeasurementResult>Server. Stores an on-device result with POST /sdk/v1/measurements and returns the stored measurement with its id.
signAndFetchMeasurement({ keyId, secret, measurementId, includeAdvanced?, includeAssessment? }): Promise<MeasurementResult>Server. Reads a stored measurement with GET /sdk/v1/measurements/{id}.
toMeasurementInput(result): MeasurementInputConverts a result to the request body of POST /sdk/v1/measurements, dropping id, keyId, createdAt, origin and attested.
SDK_VERSION: stringThe package version, "0.1.0". Results carry it as sdkVersion.
ON_DEVICE_MODELS_VERSION: stringVersion of the on-device models. On-device results carry it as modelsVersion.

The server helpers run in Node.js 20 or later. includeAdvanced: true also stores and returns the raw section — see Measurements.