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
| Platform | Language / format | Install | Status |
|---|---|---|---|
| Web | JavaScript (ESM) | Contact us | Available |
| Android | Kotlin — AAR (phasesense) | Contact us | Available (beta) — full on-device capture; per-device tuning (fps / thermal / camera) may be needed |
| iOS | Swift — SwiftPM (PhaseSense) | Not yet available | Not yet available |
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 viaortUrl/wasmBase— self-host in production. - The camera requires HTTPS or localhost. The SDK is ESM.
- China deployment: self-host the model
.onnxand WASM files — do not depend on jsdelivr / googleapis CDNs (unreliable or blocked in China).
02 Configure (Web) — PhaseSenseConfig
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:
| Field | Type | Req | Notes |
|---|---|---|---|
tenantId | string | ✅ | Your tenant ID |
apiKey | string | ✅ | pk_ (front end) |
sessionId | string | Custom session ID | |
fps | number | Capture frame rate (default 15) | |
videoFps | number | Video frame rate (independent of capture) | |
windowMs | number | Signal window in ms (default 1000) | |
consent | { assessment?: boolean } | Data-use consent | |
features | { body?, rppg? } | Enable body / heart-rate signals | |
rppgWindowSec | number | rPPG rolling window (default 20) | |
model | FaceModelOptions | Face model options | |
record | boolean | Record A/V. Required for uploadAndSubmit / ingestAndAnalyze. | |
recordAudio | boolean | Include audio track (default true) | |
apiBase | string | Required. The platform API base URL; there is no default — uploadAndSubmit() and ingestAndAnalyze() both need it. | |
emotion | EmotionConfig | On-device emotion model config (8 fields) |
03 Methods (Web)
Methods, in five groups:
| Group | Methods |
|---|---|
| Lifecycle | PhaseSense.create(cfg) · attach(videoOrStream) · start() · stop() · dispose() |
| Signals & recording | on(evt, fn) / off(evt, fn) — "signal" (one SignalPack per ~1s), "error" · stopAndFinish() → { blob, mime, durationMs, hasAudio } · getRecording() |
| Upload & analysis | uploadAndSubmit(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 devices | setVitals(v, source?) · setExternalReading(r) · setExternalHeartRate(bpm, source?) · setRadarPacket(p) |
| Data assembly | buildRawDataPackage(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
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.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.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.
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
phasesenseAAR, drop it intoapp/libs/and declare it viaflatDir. Toolchain: JDK 17, AGP 8.5 / Kotlin 1.9. - Models: place
face_landmarker.task(required) andpose_landmarker_lite.task(optional — for body) inapp/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:
PhaseSenseConfighere carries the Android fields (pk_viaapiKey,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, usesdk.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 CameraXVideoCaptureyourself; there is no one-callrecord:trueshortcut 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.