HomeProducts— Affect— PersonaTechnologyDocs— Quick Start— Authentication— Client SDK— Webhooks— ErrorsSandboxSign In
EN · 中文
SDK

Client SDK — capture behavioral signals on the front end

The client SDK opens the camera and extracts multimodal behavioral signals on-device (low-latency, per-frame) — available for Web and Android (iOS isn't available yet), all emitting the same signal format (the Signal Contract). For a personality report, one call uploads the session and triggers cloud analysis; the report comes back to your back end via a webhook.

Platforms

PlatformLanguage / formatInstallStatus
WebJavaScript (ESM)Contact usAvailable
AndroidKotlin — AAR (phasesense)Contact usAvailable (beta) — full on-device capture; per-device tuning (fps / thermal / camera) may be needed
iOSSwift — SwiftPM (PhaseSense)Not yet availableNot yet available
How to read this page. All three platforms share the same Signal Contract (face / body / physio / emotion, matching to within a 1e-9 tolerance; iOS isn't available yet), and the report path (ingestAndAnalyze() → webhook) is identical everywhere. What differs per platform is the config fields and the camera binding. The full reference below — Configure, Methods, Usage — is the Web SDK. Android and iOS expose an analogous API with native names (not identical — see the Android and iOS sections for exact fields and method names).

01 Install

Contact us for the SDK package; once you have it, import PhaseSense from @lynxin/sdk-web.

import { PhaseSense } from "@lynxin/sdk-web";
  • Peer dependency @mediapipe/tasks-vision (^0.10.14). The on-device emotion model (.onnx, ~16 MB) ships with the package; the ONNX Runtime WASM loads via ortUrl / wasmBase — self-host in production.
  • The camera requires HTTPS or localhost. The SDK is ESM.
  • China deployment: self-host the model .onnx and WASM files — do not depend on jsdelivr / googleapis CDNs (unreliable or blocked in China).

02 Configure (Web) — PhaseSenseConfig

Web only. Android and iOS use a config object of the same name (PhaseSenseConfig) but with native, platform-specific fields — do not copy the Web fields below (e.g. ortUrl / wasmBase / inWorker are WASM-specific). See the Android section for the mobile fields.

Pass a config to PhaseSense.create(). Fields:

FieldTypeReqNotes
tenantIdstring✅Your tenant ID
apiKeystring✅pk_ (front end)
sessionIdstringCustom session ID
fpsnumberCapture frame rate (default 15)
videoFpsnumberVideo frame rate (independent of capture)
windowMsnumberSignal window in ms (default 1000)
consent{ assessment?: boolean }Data-use consent
features{ body?, rppg? }Enable body / heart-rate signals
rppgWindowSecnumberrPPG rolling window (default 20)
modelFaceModelOptionsFace model options
recordbooleanRecord A/V. Required for uploadAndSubmit / ingestAndAnalyze.
recordAudiobooleanInclude audio track (default true)
apiBasestringRequired. The platform API base URL; there is no default — uploadAndSubmit() and ingestAndAnalyze() both need it.
emotionEmotionConfigOn-device emotion model config (8 fields)

03 Methods (Web)

Methods, in five groups:

GroupMethods
LifecyclePhaseSense.create(cfg) · attach(videoOrStream) · start() · stop() · dispose()
Signals & recordingon(evt, fn) / off(evt, fn) — "signal" (one SignalPack per ~1s), "error" · stopAndFinish() → { blob, mime, durationMs, hasAudio } · getRecording()
Upload & analysisuploadAndSubmit(opts?) → { session_id, video_ref, rdp, stored } · ingestAndAnalyze(clientRef, opts?) → { session_id, stored: { task_id, analyzing } }
Your backend reads the Lynxin Affect report with your server key from GET /v1/rdp/{session_id}/report (it needs report:read, which only server keys have); with ingestAndAnalyze(), both reports reach your backend through your webhook. To show analysis reports in your frontend, enable report reading (result:read:own) when you create the client key (off by default; turning it on asks for confirmation) and read them from GET /v1/analyze/status/{task_id}. Signal report (model1) fields are on the Lynxin Affect report fields page, and personality report (model2) fields are on the Lynxin Persona report fields page.
External devicessetVitals(v, source?) · setExternalReading(r) · setExternalHeartRate(bpm, source?) · setRadarPacket(p)
Data assemblybuildRawDataPackage(video?)

04 Usage patterns

① On-device signals (client key)

const sdk = await PhaseSense.create({
  tenantId, apiKey: "pk_…", consent: { assessment: true },
});
sdk.on("signal", (pack) => {
  // one SignalPack per ~1s: face / body / physio / emotion
});
sdk.on("error", (e) => console.error(e));  // camera denied, model load…
await sdk.attach(videoEl); await sdk.start();

② ingestAndAnalyze() (Lynxin Persona)

const sdk = await PhaseSense.create({
  tenantId, apiKey: "pk_…", record: true, consent: { assessment: true },
});
await sdk.attach(videoEl); await sdk.start();
// …later:
const r = await sdk.ingestAndAnalyze("user_20394");
// r = { session_id, stored: { task_id, analyzing } }
// analyzing is false if this key lacks analyze:trigger · report → webhook in ~5–15 min
Which product you get depends on which function you call. Lynxin Affect only: turn on “signals ready” (ingest.completed) in your webhook settings, then call uploadAndSubmit() after recording, without the analyze option. This SDK function uploads the recording to the platform; once it is stored, your webhook receives an ingest.completed (signals ready) event with the session_id and a basic summary. Your backend then reads the full Lynxin Affect report with your server key from GET /v1/rdp/{session_id}/report. Lynxin Persona: call ingestAndAnalyze(clientRef). This SDK function stops recording, uploads, and triggers analysis; the client key must have Personality Profiling enabled. About 5–15 minutes later, the analysis.completed (analysis complete) webhook event delivers two reports to your backend: the signal report and the personality report. Call only one of these functions for a recording. If you called uploadAndSubmit() and later want Lynxin Persona, you don't need to record again: have your backend call POST /v1/analyze/full/submit with your server key (it needs analyze:write) and pass the recording's rdp_session_id; the platform reuses the session's signals, fills in Pro video and audio, and produces both reports. A client key can't trigger this.
With ingestAndAnalyze(), the platform runs Pro video extraction and audio extraction on the server for you, so the report includes sentence-level transcripts, speech emotion and Pro video curves. With uploadAndSubmit() only, the Lynxin Affect report doesn't include them by default; when you need them, your backend calls the extraction endpoints, billed in credits: the actual length of the audio or video is converted to tokens, then to credits.
Track progress. While the report is computed (about 5–15 minutes), your frontend can poll GET /v1/analyze/status/:task_id with a client key to drive an “analyzing…” state: pending → running → success | failed. By default it returns status only; if report reading is enabled for the key, result includes both reports when the job succeeds. Without report reading, a successful job returns status: success with result: null and result_withheld: true. That is final: stop polling and let your backend get the report (from the webhook, or with your server key). Treat your server-side checks as the only access control. (Simplest UX also works: skip polling, show “analyzing…”, and update when your backend receives the webhook.) Signal report (model1) fields are on the Lynxin Affect report fields page, and personality report (model2) fields are on the Lynxin Persona report fields page.

③ stopAndFinish() + uploadAndSubmit() (Lynxin Affect)

await sdk.stopAndFinish();      // ② ingestAndAnalyze finalizes this for you
const r = await sdk.uploadAndSubmit();   // no analyze option → Lynxin Affect only
// r = { session_id, video_ref, rdp, stored }  (snake_case; task_id in stored)

External devices

Feed vitals from a radar, oximeter, or watch — external readings take precedence over rPPG and are aligned to the video timeline automatically.

sdk.setVitals({ heart_rate: 72, respiration_rate: 16, spo2: 98 }, "watch");
sdk.setExternalHeartRate(72, "radar");

05 Signal output

Each pack (~1s) carries objective behavioral measures: face (AUs, gaze, blink, head pose, smile), body (posture openness, gesture stability, torso lean), physio (a non-contact heart-rate estimate, known as rPPG: it estimates heart rate from subtle skin-colour changes in the face on video; shows -- when the two algorithms disagree — this is by design), emotion (8-class distribution + valence/arousal, on-device — falls back to a lower-precision geometric approximation, flagged is_approximate: true, if the model can't load). A single signal alone is not a conclusion.

Emotion = 8 classes + valence/arousal (two axes). The on-device component and the cloud report use the same two axes.

06 Android SDK — Kotlin / AAR

Same Signal Contract as Web; on-device capture via CameraX + MediaPipe. The config fields and method names are native — this section is a quick start.

  • Install: contact us for the SDK package; once you have the phasesense AAR, drop it into app/libs/ and declare it via flatDir. Toolchain: JDK 17, AGP 8.5 / Kotlin 1.9.
  • Models: place face_landmarker.task (required) and pose_landmarker_lite.task (optional — for body) in app/src/main/assets/. These are the standard MediaPipe task models — download them from the MediaPipe model index. The emotion model is optional (falls back to a geometric approximation, is_approximate: true, like Web).
val sdk = PhaseSense.create(context, PhaseSenseConfig(/* pk_, tenantId, … — native fields; see build guide */))
sdk.onSignal { pack -> /* one SignalPack per ~1s: face / body / physio / emotion */ }
sdk.bindCamera(lifecycleOwner)   // CameraX — pass a LifecycleOwner (Activity/Fragment)
  • Config: PhaseSenseConfig here carries the Android fields (pk_ via apiKey, tenantId, capture options) — not the Web fields above.
  • Lifecycle: the call sequence mirrors Web conceptually — create → bind camera → run → stop → release. Do not assume the Web names.
  • Upload and trigger: sdk.uploadAndSubmit(videoFile) uploads the recording without triggering analysis; for Lynxin Persona, use sdk.ingestAndAnalyze(…) instead, which uploads the recording and triggers analysis if the key you use has Personality Profiling enabled. sdk.submitSignalsOnly() submits signals only. (With recording, you wire CameraX VideoCapture yourself; there is no one-call record:true shortcut like Web.)
  • On real devices, tune per device model: capture fps / thermal throttling / front-camera mirror / recording. Geometry and the Signal Contract stay identical across platforms (to within a 1e-9 tolerance).

07 iOS SDK — Swift / SwiftPM (not yet available)

The iOS SDK is not yet available for installation. Installation steps will be published on this page when it is.

Until iOS ships, use Web or Android for on-device capture.

08 Next steps