Docs
Contact

Web SDK

Run the face video and voice checkups in your web page, in an iframe: set it up, start it, read its results.

The Web SDK runs the face video, voice, selfie and body composition checkups inside your web page. The checkup is a page YOU(th) hosts, which you put in an <iframe>: it asks for the camera or the microphone, guides the person through the measurement, and hands the biomarkers to your page. Your page never handles the video or the recordings.

These pages describe Web SDK 0.8.0. The checkup names its own version in its ready message.

The checkup's address is https://sdk.youth-platform.io. You build and test with your test key on it, and go live by swapping that key for your live key. Nothing else changes.

What your page needs

  • A test key, pk_test_…, which your organization's admins issue in the YOU(th) console, under SDK, Keys. Keys says how keys work.
  • Its origins. List the origins your pages run on, such as https://app.example.com, in the console under SDK, Access, or tell your YOU(th) contact. Once your organization has a list, the checkup refuses a page from any other origin, with ORIGIN_NOT_ALLOWED.
  • HTTPS. Browsers only allow the camera on secure pages. localhost counts as secure while you develop.
  • Cross-origin isolation. Send these two headers with the page that holds the iframe:
Cross-Origin-Opener-Policy: same-originCross-Origin-Embedder-Policy: require-corp

With them, everything your page loads from another site must allow it, through CORS or a Cross-Origin-Resource-Policy header. The checkup's own files do, but a chat widget, a video or an analytics script on the same page may not, and stops loading. So put the checkup on a page of its own, and send the headers with that page only. Open that page with a full page load: a route change inside a single-page app keeps the headers of the page the app was loaded with.

  • Room for it. At least 320 × 480 pixels in portrait, and 640 × 360 in landscape.
  • A current browser. Safari 18 or later, on iPhone, iPad or Mac, or Chrome or Edge 113 or later. On an iPhone or iPad every browser runs on Safari's engine, so iOS 18 or later is what counts. The body composition checkup needs Safari 18.4 or later, so iOS 18.4 on an iPhone or iPad: it records its video as WebM, which Safari records from 18.4. Firefox is not supported. Check the version before you offer the checkup.
  • The wellness statement. The results are not for medical use: tell the person so.

Start a checkup

Add an iframe, without its address:

<iframe id="checkup" title="Health checkup" style="width: 100%; height: 640px; border: 0"></iframe>

Load YOU(th)'s script, which defines YouthSDK. It is pinned to its version and its integrity, so it never changes under your page; a new version comes with a new address and a new integrity:

<script  src="https://sdk.youth-platform.io/web-sdk/0.8.0/web-sdk.min.js"  integrity="sha384-UIb80k6Aj079fRjja+OnOD/QAs5wMZwsoXJ/Osax0aQqAsewA7uoXDKmlv8M6wHj"  crossorigin="anonymous"></script>

Then start the checkup with your key:

<script>  const stop = YouthSDK.startCheckup(    document.getElementById("checkup"),    "https://sdk.youth-platform.io/embed.html",    { apiKey: "your test key" },    {      onResult: (biomarkers) => console.table(biomarkers),      onError: (code, detail) => console.error(code, detail?.message),    },  );</script>

In a web app with a build step, install the same code from npm in place of the script tag:

npm install @youth-healthtech/web-sdk
import { startCheckup } from "@youth-healthtech/web-sdk";const stop = startCheckup(  document.getElementById("checkup") as HTMLIFrameElement,  "https://sdk.youth-platform.io/embed.html",  { apiKey: "your test key" },  {    onResult: (biomarkers) => console.table(biomarkers),    onError: (code, detail) => console.error(code, detail?.message),  },);

The package has no dependencies, and each of its versions has the same code as the script of that version. In React, start the checkup in an effect and return stop as its cleanup: starting again on the same iframe stops the earlier checkup first, so each event arrives once.

Open the page on a device with a camera, allow the camera, press record and hold still in even light for about a minute. onResult then receives the biomarkers: Results says what they hold. If onError says INVALID_API_KEY, check the key; if it says ORIGIN_NOT_ALLOWED, check that your page's origin is on your organization's list. The errors list the rest.

startCheckup lets the iframe use the camera and the microphone, loads the checkup and listens only to it. stop() unloads the checkup, which lets go of the camera and the microphone: call it when the person is done.

A page that cannot load the script can speak the messages itself.

Tell it about the person

The measurement is better with the person's profile, and some biomarkers need it. Send it as user. Every field is optional, except for body composition. Send age, height and weight together: some measurements use the profile only when all three are there and plausible.

{  "apiKey": "your test key",  "user": {    "age": 42,    "gender": "female",    "height": 168,    "weight": 61.5,    "smokingState": "nonSmoker"  }}
FieldValue
ageYears
genderfemale, male or unspecified
heightCentimetres
weightKilograms
smokingStatesmoker, nonSmoker or unspecified

Send smokingState whenever you know it. Face video model 1 returns ascvd_risk, ascvd_risk_level and heart_age together, and only when gender and smokingState are set, not unspecified, the age is 18 to 80 and the BMI from height and weight 15 to 50; with one missing, all three are. Model 2 is told nothing about the person and never returns them.

Choose the face video model

The face video checkup measures with a YOU(th) model. There are two, faceVideo1 and faceVideo2, the same as in the Flutter SDK, and YOU(th) sets which of them your key may run, separately for your test and live keys. Name one with model:

{ "apiKey": "your test key", "model": "faceVideo1" }
modelWhich model runs
Left outModel 1 when your key offers it, otherwise model 2
faceVideo1Model 1
faceVideo2Model 2
autoThe model the person's profile suits, among those your key offers: see the rules

The person's profile chooses the model only with auto. A model your key does not offer ends the checkup with NO_PROVIDER_AVAILABLE before the camera starts, and no other model runs in its place. Model 2's library sends data of its own: Data and privacy says what.

Model 2 measures until it has 45 seconds of footage it can use. Moments it can't use, such as while the face is being placed, don't count, so its measurement can run longer, by an amount that varies.

Name a model when your product relies on a biomarker only one model returns, or when results must stay comparable across a person's measurements. Every result names the model and the version that produced it: see What a biomarker holds.

The next person

YouthSDK.nextCheckup starts again with another profile, or another checkup, without loading the iframe again. A measurement under way is dropped:

<script>  YouthSDK.nextCheckup(    document.getElementById("checkup"),    "https://sdk.youth-platform.io/embed.html",    { user: { age: 35, height: 180, weight: 78, gender: "male" } },  );</script>

It replaces the last checkup's settings: send every field you need again, such as user, model, checkupType and voiceType. It is also how you try again after the measurement could not load: see Errors.

The voice checkups

Send checkupType: "voice" to run a voice checkup instead of the face video one, and voiceType to choose it:

voiceTypeThe personResults
respiratorySays "Aahh" twice, six seconds each. DefaultOne biomarker, respiratory_symptoms_score
mentalDescribes their day for 30 secondsEight voice features of mental fitness
{ "apiKey": "your test key", "checkupType": "voice", "voiceType": "mental" }

The voice checkups work best on a phone held close. On a computer or a kiosk the microphone is farther away and the room noisier: ask the person to come close to the microphone and speak up, and expect results there to be less reliable than on a phone.

The recordings leave the device for analysis: tell the person so before they record. While they record, onProgress also says which recording it is. A voice error carries a reason as well as its code: see Errors, and Results for the biomarkers.

The selfie checkup

Send checkupType: "faceSelfie" to take one photo of the person's face and return up to ten skin biomarkers, such as redness, hydration, lines and perceived age:

{ "apiKey": "your test key", "checkupType": "faceSelfie" }

The selfie takes nothing of the person; send user, with their age and gender, only for YOU(th)'s scores. It needs the camera alone: an iframe you write yourself needs at least camera and cross-origin-isolated in its allow.

  1. The person places their face. The checkup checks in the browser that one face is in the frame, close enough, centred, looking straight ahead and in good light, and says what to change. No frame leaves the device while it does.
  2. A short countdown starts once all is right, and the photo is taken.
  3. The person checks the photo, and taps Submit, or Retake for a new one.
  4. The photo is analysed, usually in 5 to 15 seconds, and onResult receives the biomarkers: see Results.

progress says ready, with progress: 0, while the camera waits for a good frame, and processing, with progress: 100, while the photo is sent and analysed. On its first use the browser downloads the face detector, about 17 MB from YOU(th)'s own address, with a progress bar; later checkups use the browser's cache. After an error the checkup goes back to the camera for a new photo without saying what happened, so your page tells the person; only a missing camera, or a key without the selfie, keeps its message on the checkup's screen. A selfie error carries a reason as well as its code: see Errors.

Tell the person before they start:

  • The photo leaves the device. The face check stays in the browser, but the photo they submit is sent for analysis. The checkup keeps it in memory only. Data and privacy says what is sent and kept.
  • A connection is needed from the moment they submit the photo until the results arrive.
  • Even light makes the photo clear: facing a window or a soft light, without glasses, make-up or hair over the face.

The checkup is counted once the person submits the photo, whatever happens next: a new photo after an error is a new checkup.

Body composition

Send checkupType: "bodyComposition" to measure the person's body composition from a short video of their whole body, taken as they turn around in front of the camera. It needs the person's profile, every field of it:

{  "apiKey": "your test key",  "checkupType": "bodyComposition",  "user": { "age": 42, "gender": "female", "height": 168, "weight": 61.5 }}
FieldValue
ageYears, up to 126 (a year of birth from 1900)
genderfemale or male
heightCentimetres, from 50 to 250
weightKilograms, from 20 to 500

A profile that lacks one of them, says unspecified, or holds a value outside these ranges ends the checkup at once with INVALID_USER_DATA, before anything leaves the device. The analysis is told the year of birth, worked out from the age, not the age itself.

The checkup shows its own screens: what to do, then the camera, which guides the person into the frame and through the turn, with spoken hints. Then it sends the video and waits for the analysis, which takes one to two minutes: the checkup says processing and its progress counts that time. It then shows the results and hands them to onResult: six biomarkers, see Results. If something fails, it shows what, offers to try again when a new try can help, and onError receives the code: see Errors.

Beside the results, the checkup shows the person's body in 3D, which they can turn, or a picture of it where the browser can't draw 3D. Under the results it offers Future Me: the same body at a lower weight the person picks, under their own and no lower than a healthy body mass index (18.5) allows. A checkup can make three, each in a minute or so, and they are not counted. The 3D model and Future Me stay on the checkup's screen while its session lasts: onResult receives the biomarkers alone, and the page's messages don't change.

Tell the person before they start:

  • A phone gives the best results. The analysis is made for a phone's camera, set down upright at waist height, so offer the checkup on the person's phone rather than a laptop or a kiosk. Its results on the web are less accurate than in an app.
  • The whole body must be in the frame, head to feet, and only one person in it.
  • The results take one to two minutes after the video, while the page stays open.

On an iPhone or iPad the checkup needs iOS 18.4 or later, and Safari 18.4 or later on a Mac: see What your page needs.

The video and the profile leave the device for analysis: tell the person so before they start. Data and privacy says what is sent. The checkup is counted once its video is sent, not when it starts.

YOU(th)'s scores

Each checkup can also hand your page YOU(th)'s scores of its result: the scores every YOU(th) product shows, worked out by YOU(th)'s service for the person's age and sex. Your organization gets them always with the YOU(th) app; otherwise ask your YOU(th) contact. Pass onScores, and onScoresError to hear why a result came without them:

startCheckup(iframe, "https://sdk.youth-platform.io/embed.html", settings, {  onResult: (biomarkers) => save(biomarkers),  onScores: (scores) => showScores(scores),  onScoresError: (code) => showNoScores(code),  onError: (code, detail) => console.error(code, detail?.message),});
  • The result comes first, as without scores. Then onScores gets the scores, or onScoresError says why there are none. The result stays valid either way.
  • Passing onScores asks for them. Without it nothing is asked, none of the result's values leave the checkup for scoring, and no result waits.
  • The person needs an age from 18 to 120 and a gender of female or male in user. Without them, onScoresError gets PROFILE_INCOMPLETE and nothing is asked: the checkup never assumes an age or a sex. Each nextCheckup scores its own person.
  • No connection, no answer within 8 seconds, or a refusal of YOU(th)'s service is SCORES_UNAVAILABLE. The result waits that long at most.
  • Without scores for your organization, neither callback is called.

A page that speaks the messages itself sends scores: true in init, and finds scores or scoresError on each result. The reference lists what the scores hold. A biomarker YOU(th) does not score, such as heart age, has none. YOU(th) keeps neither the scores nor the person's profile.

Make it yours

Start the checkup with your key alone, and it takes your organization's settings from the YOU(th) console. A field you pass when you start it wins over the saved one:

  • Language. locale takes English, German, Italian or Spanish (en, de, it, es); a region such as de-CH counts as its language, and any other gives way to your organization's saved language, or English.
  • Look. theme sets the footer's and the record button's colours, and the texts' colour, size, weight and font. A font must be installed on the person's device.
  • Words. messages replaces the checkup's texts, by key.
  • Layout. orientation is portrait, the default, or landscape, for a screen wider than tall. mediaShare, which only your page sets, gives the picture a share of the iframe, for a large screen: see On a kiosk.
  • Error reports. diagnostics: false turns the checkup's error reports off.

The reference lists each one.

On a kiosk

The checkup fills its iframe. In portrait the picture is on top and a panel with the texts and the button is under it; in landscape the panel is on the right. The panel is only as large as its content, about 260 pixels tall with texts of 14 to 18 pixels, and the picture takes the rest. On a phone that is right. On a tall kiosk screen it leaves the picture nearly the whole screen and the instructions small at the bottom edge.

mediaShare sets the share of the iframe the picture takes: a number from 0.2 to 0.9, of the height in portrait and of the width in landscape. The panel gets the rest, and its texts, its button and the space between them are drawn larger together to fill it:

{ "apiKey": "your test key", "orientation": "portrait", "mediaShare": 0.6 }

On a 1080 by 1920 screen, 0.6 gives the picture the top 1152 pixels and draws the panel's content about 2.3 times larger: texts of 32 to 41 pixels and a button of about 175. Half the screen draws half of everything, so one share suits a screen at any size. A screen too small for the share keeps the panel whole and gives the picture what is left: the panel is never smaller than its content, and in landscape never narrower than it is without a share, 300 to 400 pixels. A high share stops there. A value the checkup cannot read leaves the layout as it is without one.

Choose the share with the camera in mind. Face video model 1 fills its area with the camera's picture and crops what does not fit, so a picture wider than the area, as a 16:9 camera's is on a portrait screen, shows the face larger the taller the area is. In a 1080 × 1920 iframe, a 16:9 picture shows the face about 1.9 times larger at 0.6 than it would be with the whole picture across the width, and only a little larger at 0.35; in a shorter iframe, less. Model 2 shows its picture whole, with bars where the area has another shape. Sizes you set in theme are sizes before the drawing grows.

Leave a minute or two between face video checkups on the same kiosk when you can: model 1's measurement works the device hard.

The voice checkups use the same layout and take the same share, with their animation in place of the picture. You can also give the checkup a smaller iframe and use the rest of the screen yourself: the same rules apply inside whatever size it gets.

Test your integration

Before you swap in your live key, run through these with your test key, on the devices and screens your customers will use. Test checkups are never billed, but each counts against your test key's monthly limits.

  • Your origins. Open the page from each origin it runs on. Once your organization lists origins, a page from any other origin receives ORIGIN_NOT_ALLOWED.
  • The camera. Allow it when the browser asks. Refuse it once too: onError receives CAMERA_UNAVAILABLE. The checkup does not tell the person, so your page does.
  • A whole face video checkup. Press record and hold still in even light for about a minute: onResult receives the biomarkers.
  • A voice checkup, if you offer one. Run one to its result, and refuse the microphone once: onError receives MICROPHONE_UNAVAILABLE, with the reason permissionDenied.
  • A selfie checkup, if you offer one. Run one to its result in even light, and start one in a dim room once: the checkup asks for more light before it takes the photo.
  • A body composition checkup, if you offer one. On a phone, run one to its result, which takes a couple of minutes after the video. Send a profile without gender once: onError receives INVALID_USER_DATA before the camera opens.
  • The next person. Start another checkup with nextCheckup and another profile: it starts without loading the iframe again. If your page lets the person cancel, cancel during a measurement: nextCheckup drops the measurement under way, and stop() unloads the checkup.
  • On a kiosk, choose mediaShare on the real screen, with the camera where it is mounted: see On a kiosk.

Without the script

A page that does not load the script speaks the messages itself. The checkup says ready once, as soon as it has loaded, so listen before you load it. Your page answers ready with init, sent to the checkup's exact origin, never to "*", because it carries your key. Listen only to the iframe's own window and origin. A checkup that cannot load never says ready, so stop waiting after a while. The iframe needs allow="camera; microphone; cross-origin-isolated".

/** A blood pressure, in mmHg. */export type BloodPressure = { systolic: number; diastolic: number };export type Biomarker = {  type: string;  name: string;  value: number | string | BloodPressure;  unit: string;  model: string;  modelVersion: string;};/** Which recording of a voice checkup a `progress` is about. */export type Recording = { step: number; steps: number };/** What the checkup adds to an error: a voice error's `reason`, and a `message` for your logs. */export type ErrorDetail = { reason?: string; message?: string };export type CheckupEvents = {  onProgress?: (state: string, progress: number, recording?: Recording) => void;  onResult: (biomarkers: Biomarker[]) => void;  onError: (code: string, detail?: ErrorDetail) => void;};/** How long the checkup may take to load before `onError("LOAD_TIMEOUT")`. */const LOAD_TIMEOUT_MS = 30_000;/** * Loads the checkup at `address` into `iframe` and runs it with `settings`. Returns a function * that stops listening. */export function startCheckup(  iframe: HTMLIFrameElement,  address: string,  settings: Record<string, unknown>,  events: CheckupEvents,): () => void {  const origin = new URL(address).origin;  function onMessage(event: MessageEvent) {    // Only the checkup in this iframe, from its own origin.    if (event.source !== iframe.contentWindow || event.origin !== origin) return;    const message = event.data;    // Not a message of the checkup's at all: a script on its page may post to yours too.    if (typeof message?.v !== "number") return;    // Messages of another version are not understood here: say so once rather than wait.    if (message.v !== 2) {      stop();      events.onError("UNSUPPORTED_VERSION");      return;    }    if (message.type === "ready") {      clearTimeout(loading);      // To the checkup's origin only: the settings carry your key.      iframe.contentWindow?.postMessage({ v: 2, type: "init", payload: settings }, origin);    } else if (message.type === "progress") {      const { state, progress, step, steps } = message.payload;      events.onProgress?.(state, progress, step === undefined ? undefined : { step, steps });    } else if (message.type === "result") {      events.onResult(message.payload.biomarkers);    } else if (message.type === "error") {      const { code, reason, message: text } = message.payload;      events.onError(code, { reason, message: text });    }  }  function stop() {    clearTimeout(loading);    window.removeEventListener("message", onMessage);  }  // Listen first: `ready` comes once, as soon as the checkup has loaded.  window.addEventListener("message", onMessage);  // A checkup that loads after this is ignored.  const loading = setTimeout(() => {    stop();    events.onError("LOAD_TIMEOUT");  }, LOAD_TIMEOUT_MS);  iframe.src = address;  return stop;}

To start again with the next person, send checkup to the checkup's origin:

{  "v": 2,  "type": "checkup",  "payload": { "user": { "age": 35, "height": 180, "weight": 78, "gender": "male" } }}

Moving from the earlier Web SDK

A page built on the earlier Web SDK, at the address your YOU(th) contact gave you before, moves with a few changes:

  • A new address and new keys. Load the checkup from https://sdk.youth-platform.io/embed.html, and start it with a key issued in the console, not your earlier one.
  • No environment. The key decides whether a checkup is a test, so leave environment out. A page that still sends it keeps working: the checkup ignores it.
  • model replaces selectedProvider. selectedProvider keeps working when you send no model. A checkup that names neither runs model 1, or model 2 when your key offers only that, where the person's profile chose before: send model: "auto" to keep that. See Choose the face video model.
  • Version 2 of the messages. The messages are the earlier ones, with the same types and fields, but their v is 2, and each biomarker in a result takes YOU(th)'s catalog's code and value: see the changelog. A page that answers ready with init and listens to progress, result and error keeps working once it sends and reads version 2. They have also gained fields: ready carries the checkup's version, and each biomarker its model and modelVersion. Keep your own code, or load YOU(th)'s script instead: see Start a checkup.
  • New biomarker codes and values. Biomarkers take the codes of YOU(th)'s catalog, such as hrv_mean_rri for hrv_rri, blood pressure is one biomarker with both numbers, and a level is its word, such as low, not its number. See Results and the changelog.
  • New refusals. A page from an origin your organization does not list gets a new code, ORIGIN_NOT_ALLOWED. A checkup past its monthly limit gets SERVICE_UNAVAILABLE. Until YOU(th) has set your limits, your key opens no checkup: a face video checkup ends with NO_PROVIDER_AVAILABLE, and a voice checkup with NETWORK. INVALID_API_KEY, ORIGIN_NOT_ALLOWED and SERVICE_UNAVAILABLE can also come after initialized: the errors say when.
  • More time for a slow measurement. A face video measurement that needs longer than its minute gets up to two minutes more, where it got 30 seconds. The minute starts once the face is in place, up to 90 seconds after the person presses the button, so a result can come up to four and a half minutes after the press. Leave that room in your page's own timeouts.
  • Safari 18. On a Mac the checkup now needs Safari 18 or later, as on an iPhone or iPad.

Last updated