FacePair
Quick start
Use your dashboard client key in the browser. Set VOLTOM_SECRET_KEY on your server. These examples use authenticated Express routes.
npm install @voltom.io/sdkView the FacePair demo source on GitHub
Match reference
Pass an image or PDF to acquireReference before capturing the face.
Server · Create intent
app.post('/api/facepair/match-reference/intent', async (request, response) => {
const upstream = await fetch('https://api.voltom.io/facepair', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
authorization: `Bearer ${process.env.VOLTOM_SECRET_KEY}`,
},
body: JSON.stringify({}),
});
if (!upstream.ok) return response.sendStatus(upstream.status);
const intent = await upstream.json();
request.session.facePairResultId = intent.id;
response.json(intent);
});Browser
import VoltomFacePair from '@voltom.io/sdk/facepair';
const sdk = new VoltomFacePair({ clientKey: 'YOUR_CLIENT_KEY' });
const start = async (file: Blob) => {
const response = await fetch('/api/facepair/match-reference/intent', { method: 'POST' });
const intent = await response.json();
const result = await sdk.verify(intent, file);
if (result === null) return;
const decision = await fetch('/api/facepair/match-reference/complete', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ resultId: intent.id }),
});
if (decision.ok) window.location.assign('/account');
};Server · Verify result
app.post('/api/facepair/match-reference/complete', async (request, response) => {
const { resultId } = request.body;
if (resultId !== request.session.facePairResultId) return response.sendStatus(403);
const upstream = await fetch(`https://api.voltom.io/facepair/${resultId}`, {
headers: { authorization: `Bearer ${process.env.VOLTOM_SECRET_KEY}` },
});
if (!upstream.ok) return response.sendStatus(upstream.status);
const outcome = await upstream.json();
if (outcome.status !== 'resolved') return response.sendStatus(403);
if (outcome.outcome !== 'pass') return response.sendStatus(403);
await commitVerificationOnce({ request, resultId });
response.json({ completed: true });
});acquireReference(file) accepts an image or PDF Blob up to 10 MB. PDFs use page 1, rendered at up to 1200 pixels. Images can contain multiple faces. Changing the reference clears existing face captures. verify(intent, file) uses one intent for the reference, the live face, and the final match. If the SDK rejects the reference, it asks the user to select another file. The final match fails with FACE_MISMATCH when the faces do not match.
Expired intent tokens fail with INTENT_TOKEN_INVALID. Retry the whole operation with a fresh intent.
Configuration Reference
| Option | Type | Default | Description |
|---|---|---|---|
clientKey | string | Required | Public client key from the VOLTOM dashboard. |
faceMeshColor | string | #38efb0 | Face mesh line color. |
faceOverlayColor | string | transparent | Face overlay fill color. |
language | Language | Browser language, then en | SDK interface language. Supports ar, ch, de, en, es, fr, it, ja, pt, ru, zh. Chinese locales zh-TW, zh-HK, and zh-MO select ch. |
poses | Pose[] | 'all' | faceStraight, faceUp, faceLeft, faceRight | Requires these four poses, no duplicates, and faceStraight first. Additional poses: faceDown, faceSmile, faceWinkLeft, faceTiltLeft, faceTiltRight. |
prepare | boolean | true | Prepares the SDK at construction. Set false to prepare on demand. Camera access starts when an operation runs. |
showFaceOverlay | boolean | false | Draws the face detector overlay. Separate from capture guidance. |
theme | 'light' | 'dark' | Host theme, then system | Overrides host .light, .dark, or data-theme selectors and system preference. |
Instance Options Reference
Use configure(options) to update instance options. Each flow reads a snapshot at startup. Changes during a flow apply to its next run, including retry. Use stop() to cancel. Omitted options and undefined retain current values.
| Option | Type | Default | Description |
|---|---|---|---|
poses | Pose[] | 'all' | Instance value | Requires these four poses, no duplicates, and faceStraight first. Additional poses: faceDown, faceSmile, faceWinkLeft, faceTiltLeft, faceTiltRight. |
showFaceOverlay | boolean | Instance value | Draws the face detector overlay. Separate from capture guidance. |
Methods Reference
| Method | Result |
|---|---|
acquireFace() | Captures and verifies a live face. Call match() to compare it with the reference. Throws CAPTURES_INCOMPLETE when no reference exists. |
acquireReference(file) | Prepares the image, submits it to PUT /facepair/{id}/reference, and returns whether the reference was accepted. |
begin(intent) | Starts one intent for manual capture. Repeating the start records one usage unit in total. |
caniuse() | Returns { supported, unsupportedFeatures } for the current browser. |
configure(options) | Updates poses, overlays, and debug. Invalid values throw INVALID_OPTIONS for the next flow. |
dispose() | Disposes the client permanently. Releases the camera, removes subscriptions, and clears collected data. Create a new client to continue. |
forgetFace() | Clears face captures, matching state, and the stored face verification identifier. Emits voltom:captures-change. |
forgetReference() | Clears the stored reference and its preview. Throws OPERATION_IN_PROGRESS during a flow. |
getState() | Returns the current FacePairPresentationState snapshot. |
match() | Compares the verified reference and face. Both acquisitions must succeed on this instance first. |
preload() | Loads the language and models before a verification flow. Rejects with MODEL_LOAD_FAILED on failure. |
prepare() | Calls preload(), validates the client key, initializes models, and prepares the capture interface. The constructor calls it unless prepare is false. |
stop() | Aborts the active operation with OPERATION_CANCELLED, stops the camera, and closes the overlay. |
subscribe(listener) | Observes presentation state changes and returns an unsubscribe function. |
verify(intent, file) | Runs the capture steps and match. Returns true, false, or null. |
Results
Technical failures and cancellation reject the operation with a VoltomSdkError. Completed verification and match rejections return a result. Use error.code for decisions. error.message contains stable English text; the SDK UI translates messages separately. HTTP errors include status. Errors for completed results include resultId when available.
import { Errors, isSdkError } from '@voltom.io/sdk/facepair';
try {
const result = await facePair.match();
console.log(result);
} catch (error) {
if (!isSdkError(error)) throw error;
if (error.code !== Errors.OPERATION_CANCELLED) {
console.error(error.code, error.message, error.status, error.resultId);
}
}Script integrations use VoltomFacePair.Errors and VoltomFacePair.isSdkError. Shared codes include OPERATION_CANCELLED, OPERATION_TIMEOUT, OPERATION_IN_PROGRESS, SDK_DISPOSED, INTENT_TOKEN_INVALID, NETWORK_ERROR, and INVALID_SERVICE_RESPONSE. Cancellation and network errors do not confirm whether a server operation completed. Resolve the result on your server before you retry a protected action.
Capture methods return true when accepted, false for a retake, and null on cancellation. The final result is available from match(), verify(), and sdk.result. Technical errors reject the promise. Read the outcome on your server before applying the business action.
Events
Listen for these events on facePair.events.
| Event | When it fires | Event data |
|---|---|---|
voltom:in-progress | A verification operation starts. | None |
voltom:ready | A verification operation finishes, including after an error. | None |
voltom:camera-change | Camera activity changes. | { active: boolean } |
voltom:captures-change | Captured data changes. | FacePairCaptureResult |
Useful fields of the voltom:captures-change payload include captures, documentCodes, and identity. Entries in captures are Blob images keyed by pose or reference, for example captures.faceStraight or captures.reference.
type FacePairCaptureResult = {
identity: IdentityPayload | null;
captures: FacePairCaptures;
documentCodes: DocumentCode[];
preparedCaptures: FacePairPreparedCaptures;
document?: ClassifiedDocument;
};facePair.events.addEventListener('voltom:in-progress', () => {});
facePair.events.addEventListener('voltom:ready', () => {});
facePair.events.addEventListener('voltom:camera-change', (event) => {
console.log(event.detail.active);
});
facePair.events.addEventListener('voltom:captures-change', (event) => {
const faceCapture = event.detail.captures.faceStraight;
console.log(faceCapture); // Blob | undefined
});REST API
Create the intent on your server with the secret key, consume it in the browser with the SDK, then resolve the outcome on your server with the secret key.
Send Authorization: Bearer YOUR_SECRET_KEY from your server. POST requests use Content-Type: application/json. Successful responses return HTTP 200 and JSON. The TypeScript shapes below describe JSON payloads; ? marks optional fields. Response timestamps use ISO 8601. ErrorCode values use the SDK error codes listed above. GET requests read an outcome; they do not run the protected application action.
| Method | URL | Key | Purpose |
|---|---|---|---|
PUT | https://api.voltom.io/facepair/{id}/error | Public or secret key | Record a terminal camera or model loading error on the active intent. |
POST | https://api.voltom.io/facepair | Secret key | Create one intent for the complete verification attempt. |
PUT | https://api.voltom.io/facepair/{id}/begin | Public or secret key | Start the attempt and record one usage unit. |
PUT | https://api.voltom.io/facepair/{id}/reference | Public or secret key | Submit the locally accepted reference as an image data URL. |
PUT | https://api.voltom.io/facepair/{id}/face | Public or secret key | Submit the locally accepted face captures and poses. |
PUT | https://api.voltom.io/facepair/{id}/match | Public or secret key | Consume this intent and compare its accepted captures. Repeating the submission returns the stored outcome after completion. |
GET | https://api.voltom.io/facepair/{id} | Secret key | Read the current outcome of a FacePair result. The final submission consumes the intent. This GET only reads the result. Accept only a resolved status and pass outcome. FacePair returns the comparison decision by intent ID. |
PUT https://api.voltom.io/facepair/{id}/error
Record a terminal camera or model loading error on the active intent.
Request payload
type RequestBody = { token: string; code: ClientFlowError };Response payload
type ResponseBody = null;POST https://api.voltom.io/facepair
Create one intent for the complete verification attempt.
Request payload
{}Response payload
type ResponseBody = { id: string; token: string };PUT https://api.voltom.io/facepair/{id}/begin
Start the attempt and record one usage unit.
Request payload
type RequestBody = { token: string };Response payload
nullPUT https://api.voltom.io/facepair/{id}/reference
Submit the locally accepted reference as an image data URL.
Request payload
type RequestBody = { token: string; reference: string };Response payload
type ResponseBody = { accepted: boolean; reason: ErrorCode | null };PUT https://api.voltom.io/facepair/{id}/face
Submit the locally accepted face captures and poses.
Request payload
type RequestBody = { token: string; poses: string[]; faces: string[]; poseReference?: string; poseReferences?: string[][] };Response payload
type ResponseBody = { accepted: boolean; reason: ErrorCode | null };PUT https://api.voltom.io/facepair/{id}/match
Consume this intent and compare its accepted captures. Repeating the submission returns the stored outcome after completion.
Request payload
type RequestBody = { token: string };Response payload
type ResponseBody = {
resultId: string; outcome: 'pass' | 'fail' | 'error';
reason: ErrorCode | null; completedAt: string; createdAt: string;
};GET https://api.voltom.io/facepair/{id}
Read the current outcome of a FacePair result. The final submission consumes the intent. This GET only reads the result. Accept only a resolved status and pass outcome. FacePair returns the comparison decision by intent ID.
Request payload
// Path: id (UUID). No query parameters or request body.Response payload
type ResponseBody = {
id: string; // UUID
product: 'facepair';
status: 'pending' | 'consumed' | 'resolved' | 'expired' | 'failed';
outcome: 'pass' | 'fail' | 'error' | null;
reason: ErrorCode | null;
createdAt: string; // ISO 8601
expiresAt: string; // ISO 8601
startedAt: string | null;
processedAt: string | null;
completedAt: string | null;
};Limits and Support
The same token covers all steps and retakes. It expires after 10 minutes. The monthly allowance belongs to the billing account of the key.
For support, write to us through Contact Us. Custom integration work is separately quoted.
Pricing Explained
The standard price is $0.02 per FacePair verification flow. The default account discount is $1.00 per month.
Creating an intent is free. The first accepted browser submission counts as one unit, even if the user stops before match. Later stages and a negative match add no units. A terminal technical error removes the unit.