Bodygram
Playground

Selfie Playground

Configure the single-image selfie capture flow, launch it, and handle the captured image.

Overview

Selfie capture is the Headless SDK's single-image alternative to the two-photo Scanflow. When invoked, it embeds a guided, face-tracking camera interface that walks the user through capturing one selfie, then hands the image back to your code as a base64 JPEG you can pass straight to selfie estimation.

Unlike Scanflow, there is only one screen — the live capture view — and a smaller set of configuration options.


Implementation

Call sdk.selfie() to launch the capture flow. It returns a promise that resolves with the captured image and its dimensions once the user completes the capture.

const { image, width, height, capturedAt } = await sdk.selfie({
  facingMode: 'user',
  orientation: 'auto',
  requireGyro: false,
  isDebug: false,
});

Configuration

All fields are optional.

OptionTypeDefaultDescription
facingMode'user' | 'environment''user'Which camera to open. Selfie defaults to the front-facing camera.
orientation'auto' | 'portrait' | 'landscape''auto'Lock the capture orientation, or let the SDK pick based on the device.
requireGyrobooleanfalseWhen true, the SDK requests DeviceOrientationEvent permission on iOS before starting.
isDebugbooleanfalseRenders an on-screen overlay with face-tracking diagnostics. Useful during development.

Selfie capture loads a face-tracking model on launch, so the first capture may take a moment longer than a regular camera open. The SDK shows its own loader while the model initialises.


Error handling

sdk.selfie() returns a promise that can reject in two cases:

CodeWhen
SELFIE_CLOSED_BY_USERThe user closed the capture UI before completing the selfie.
INVALID_SELFIE_CAPTURE_PAYLOADThe capture completed but returned data that failed validation.
try {
  const { image } = await sdk.selfie(config);
} catch (err) {
  if (err.code === 'SELFIE_CLOSED_BY_USER') {
    // user dismissed the capture UI
  } else if (err.code === 'INVALID_SELFIE_CAPTURE_PAYLOAD') {
    // unexpected payload from the selfie iframe
  }
}

Try it

Configure the options below and launch the selfie capture with your client key.

Interactive Demo

Selfie

CODE
const sdk = new BodygramSDK({
  clientKey: 'YOUR_CLIENT_KEY',
  locale: 'en',
});

const { image, width, height, capturedAt } = await sdk.selfie({
  facingMode: 'user',
  orientation: 'auto',
  requireGyro: false,
  isDebug: false,
});

API reference

Detailed signatures, parameters, and response shapes for everything used on this page live in the Headless SDK API reference.

Methods

Initialization

On this page