Enroll a face
Capture one face image and submit it to the Slade ID backend as an enrollment for a specific subject.
Prerequisites
- An initialised
SladeIDinstance. - A
<video>element in the DOM. - An
enrolleeId— your system’s identifier for the subject.
Steps
- Create a
FaceCaptureSessionagainst the video element. - Listen for
'captured'. - In the listener, call
sdk.enrollFace(enrolleeId, result). - Call
session.start().
Full example
import { SladeID, type FaceCaptureResult } from '@sladeid/slade-id-sdk';
const sdk = new SladeID({
middlewareUrl: 'https://id.example.com',
clientSecret: '<ClientSecret>',
});
const video = document.querySelector<HTMLVideoElement>('#camera')!;
async function enroll(enrolleeId: string): Promise<void> {
const session = sdk.createFaceSession(video, {
requireLiveness: true,
antispoofThreshold: 0.7,
holdSteadyMs: 3000,
});
return new Promise((resolve, reject) => {
session.on('captured', async ({ result }: { result: FaceCaptureResult }) => {
try {
const enrolled = await sdk.enrollFace(enrolleeId, result);
console.log('enrolled id:', enrolled.id);
resolve();
} catch (err) {
reject(err);
}
});
session.on('error', reject);
session.start().catch(reject);
});
}
await enroll('subject-123');Response shape:
{
"id": "f3c4b2a8-...",
"enrollee": "subject-123",
"createdAt": "2026-05-14T10:00:00Z",
"raw": { "...": "untouched backend payload" }
}What can go wrong
CaptureErrorwith codeCAMERA_PERMISSION_DENIED— the user blocked the camera prompt. Surface a “permission needed” UI and link them to browser settings. See Handle camera permission denial.QualityErrorwith codeFACE_QUALITY_FAILED— couldn’t get a sharp, well-lit frame withinmaxFaceQualityRetriesattempts. Ask the user to move closer to a light source or face the camera squarely.QualityErrorwith codeANTISPOOF_FAILED— real-confidence stayed below threshold. Confirm the user is presenting a live face, not a photo.NetworkErrorwith codeREQUEST_TIMEOUT— the backend took longer thantimeoutMs(default 15 seconds). Retry; consider bumpingtimeoutMsif your network conditions justify it.AuthErrorwith codeUNAUTHORIZED— the ClientSecret is expired or rejected. Issue a fresh one.