@modelhealth/modelhealth
    Preparing search index...

    Class ModelHealthService

    Model Health SDK Client for biomechanical analysis.

    Main entry point for interacting with the Model Health SDK. Provides authentication, session management, data download, and analysis capabilities.

    const client = new ModelHealthService({
    apiKey: "your-api-key-here"
    });
    await client.init();

    // SDK is ready to use
    const sessions = await client.sessionList();
    const client = new ModelHealthService({
    apiKey: "your-api-key"
    });
    await client.init();
    Index

    Constructors

    • Create a new Model Health client.

      Parameters

      Returns ModelHealthService

      If API key is not provided

      const client = new ModelHealthService({
      apiKey: "your-api-key-here"
      });
      const client = new ModelHealthService({
      apiKey: "your-api-key",
      autoInit: false
      });

    Methods

    • Retrieves all movement activities associated with the account.

      Activities represent individual recording sessions and contain references to captured videos and analysis results. Use this to review past data or fetch analysis for completed activities.

      Parameters

      • sessionId: string

        Session identifier

      Returns Promise<Activity[]>

      An array of Activity objects

      If the request fails or authentication has expired

      const activities = await client.activityList(session.id);

      // Find completed activities ready for analysis
      const completed = activities.filter(t => t.status === "completed");

      // Access videos and results
      for (const activity of completed) {
      console.log(`Activity: ${activity.name ?? activity.id}`);
      console.log(`Videos: ${activity.videos.length}`);
      console.log(`Results: ${activity.results.length}`);
      }
    • Calibrates a camera using a checkerboard pattern.

      Requirements:

      • A printed checkerboard pattern
      • Accurate measurement of square size in millimeters
      • Multiple views of the checkerboard from different angles

      The calibration is automated and typically completes in a few seconds

      Parameters

      • session: Session

        The session created with createSession()

      • checkerboardDetails: CheckerboardDetails

        Configuration of the calibration checkerboard

      • statusCallback: (status: CalibrationStatus) => void

        Callback function called with calibration progress updates

      Returns Promise<void>

      If calibration fails (insufficient views, pattern not detected, etc.)

      const session = await client.createSession();

      const details: CheckerboardDetails = {
      rows: 4, // Internal corners, not squares (for 5×6 board)
      columns: 5, // Internal corners, not squares (for 5×6 board)
      squareSize: 35, // Measured in millimeters
      placement: "perpendicular"
      };

      await client.calibrateCamera(session, details, (status) => {
      console.log("Calibration status:", status);
      });
      // Calibration complete, proceed to neutral pose
    • Captures the subject's neutral standing pose for model scaling.

      This step is required after camera calibration and before recording movement activities. It takes a quick video of the subject standing in a neutral position, which is used to scale the biomechanical model to match the subject's dimensions.

      Instructions for subject:

      • Stand upright in a relaxed, natural position
      • Face forward with arms spread slightly at sides
      • Remain still for a few seconds

      Parameters

      • subject: Subject

        The subject to calibrate the neutral pose for

      • session: Session

        The session to perform calibration in

      • statusCallback: (status: CalibrationStatus) => void

        Callback function called with calibration progress updates

      Returns Promise<void>

      If pose capture fails (subject not detected, poor lighting, etc.)

      // After successful camera calibration
      await client.calibrateNeutralPose(subject, session, (status) => {
      console.log("Neutral pose status:", status);
      });
      // Model now scaled, ready to record movement activities
    • Creates a new session.

      A session is required before performing camera calibration. It represents a single calibration workflow and groups multiple cameras together.

      After creating a session, use camera calibration methods to calibrate your cameras.

      Returns Promise<Session>

      A Session object with a unique identifier

      If session creation fails

      // Create session
      const session = await client.createSession();

      // Proceed with calibration
      const details: CheckerboardDetails = {
      rows: 4,
      columns: 5,
      squareSize: 35,
      placement: "perpendicular"
      };
      // await client.calibrateCamera(session, details, (status) => { ... });
    • Creates a new subject in the system.

      Subjects represent individuals being monitored or assessed. After creating a subject, they can be associated with sessions for neutral pose calibration and movement activities.

      Parameters

      Returns Promise<Subject>

      The newly created Subject with its assigned ID

      If creation fails (validation errors, duplicate name, etc.)

      const params: SubjectParameters = {
      name: "John Doe",
      weight: 75.0, // kilograms
      height: 180.0, // centimeters
      birthYear: 1990,
      gender: "man",
      sexAtBirth: "man",
      characteristics: "Regular training schedule",
      subjectTags: ["athlete"],
      terms: true
      };

      const subject = await client.createSubject(params);
      console.log(`Created subject with ID: ${subject.id}`);

      // Use the subject for calibration
      // await client.calibrateNeutralPose(subject, session, (status) => { ... });
    • Deletes an activity from the system.

      This permanently removes the activity and all its associated data, including videos and analysis results. This action cannot be undone.

      Parameters

      • activity: Activity

        The activity to delete

      Returns Promise<void>

      If the deletion fails or authentication has expired

      const activity = await client.getActivity("abc123");
      await client.deleteActivity(activity);
      // Activity and all associated data are now permanently deleted

      This operation is irreversible. All videos, analysis results, and metadata associated with this activity will be permanently lost.

    • Downloads analysis result data for a completed activity.

      Parameters

      Returns Promise<AnalysisResultData[]>

      An array of analysis result data, one entry per requested type. Returns an empty array if no results are available or all downloads fail.

      const results = await client.downloadActivityAnalysisResultData(
      activity,
      ["metrics", "report"]
      );

      for (const result of results) {
      switch (result.resultDataType) {
      case "metrics":
      const json = JSON.parse(new TextDecoder().decode(result.data));
      break;
      case "report":
      // Use result.data directly as a PDF
      break;
      case "data":
      // Use result.data directly as a ZIP file
      break;
      }
      }

      Individual download failures are silently excluded from results.

    • Downloads result data files from a processed activity.

      After an activity completes processing, various result files become available for download. Use this method to retrieve specific types of data (kinematic measurements, visualizations) in their native file formats (JSON, CSV).

      This method is useful when you need access to raw analysis data rather than the structured metrics provided by analysis result methods.

      Parameters

      • activity: Activity

        The completed activity to download data from

      • dataTypes: ResultDataType[]

        The types of result data to download

      Returns Promise<ResultData[]>

      An array of result data, one entry per requested type. Returns an empty array if no results are available or all downloads fail.

      // Download kinematics in MOT format
      const results = await client.downloadActivityResultData(activity, ["kinematics_mot"]);

      for (const result of results) {
      switch (result.resultDataType) {
      case "kinematics_mot":
      // Use result.data directly as a .mot file
      break;
      }
      }

      // Download multiple types in one call
      const allData = await client.downloadActivityResultData(
      activity,
      ["kinematics_mot", "animation"]
      );
      console.log(`Downloaded ${allData.length} result files`);

      This method performs concurrent downloads for optimal performance. Individual download failures do not affect other requests and failed downloads are silently excluded from results.

    • Download video data for a specific activity.

      Asynchronously fetches all videos associated with a given activity that match the specified type. Videos with invalid URLs or failed downloads are silently excluded from the result.

      Parameters

      • activity: Activity

        The activity whose videos should be downloaded

      • version: VideoVersion = "synced"

        The version type of videos to download (default: "synced")

      Returns Promise<Uint8Array<ArrayBufferLike>[]>

      An array of video data as Uint8Array. The array may be empty if no valid videos are available or all downloads fail.

      const activity = // ... obtained activity
      const videoData = await client.downloadActivityVideos(activity, "raw");

      for (const data of videoData) {
      // Process video data
      }

      This method performs concurrent downloads for optimal performance. Individual download failures do not affect other requests.

    • Retrieves activities for a specific subject with pagination and sorting.

      This method allows you to fetch activities associated with a particular subject, with control over pagination and sort order. This is useful for displaying activity history or implementing infinite scroll interfaces.

      Parameters

      • subjectId: string

        The ID of the subject whose activities to retrieve

      • startIndex: number

        Zero-based index to start from (for pagination). Use 0 for first page.

      • count: number

        Number of activities to retrieve per request

      • sort: "updated_at"

        Sort order for the results (e.g., "updated_at" for most recent first)

      Returns Promise<Activity[]>

      An array of activities for the specified subject

      If the request fails or authentication has expired

      // Get the 20 most recent activities for a subject
      const recentActivities = await client.getActivitiesForSubject(
      "subject-123",
      0,
      20,
      "updated_at"
      );

      // Pagination - get the next 20 activities
      const nextPage = await client.getActivitiesForSubject(
      "subject-123",
      20,
      20,
      "updated_at"
      );
    • Retrieves a specific activity by its ID.

      Use this method to fetch the complete details of an activity, including its videos, results, and current processing status.

      Parameters

      • activityId: string

        The unique identifier of the activity

      Returns Promise<Activity>

      The requested activity with all its details

      If the activity doesn't exist, or if authentication has expired

      const activity = await client.getActivity("abc123");
      console.log(`Activity: ${activity.name ?? "Unnamed"}`);
      console.log(`Status: ${activity.status}`);
      console.log(`Videos: ${activity.videos.length}`);
    • Retrieves all available activity tags.

      Activity tags provide a way to categorize and filter activities. This method returns all tags configured in the system, which can be used for filtering or organizing activities in your application.

      Returns Promise<ActivityTag[]>

      An array of available activity tags

      If the request fails or authentication has expired

      const tags = await client.getActivityTags();
      for (const tag of tags) {
      console.log(`${tag.label}: ${tag.value}`);
      }

      // Use tags for filtering or categorization
      const cmjTag = tags.find(t => t.value === "cmj");
    • Retrieves the current status of an analysis task.

      Poll this method to monitor analysis progress. When status is .completed, use downloadActivityAnalysisResultData to fetch metrics, report, or raw data.

      Parameters

      Returns Promise<AnalysisTaskStatus>

      The current analysis status

      Network or authentication errors

      const status = await client.getAnalysisStatus(task);

      switch (status.type) {
      case "processing":
      console.log("Analysis running...");
      break;
      case "completed":
      const results = await client.downloadActivityAnalysisResultData(
      activity,
      ["metrics", "report"]
      );
      const metricsEntry = results.find((r) => r.resultDataType === "metrics");
      if (metricsEntry?.data) {
      const metrics = JSON.parse(new TextDecoder().decode(metricsEntry.data));
      console.log("Metrics:", metrics);
      }
      break;
      case "failed":
      console.log("Analysis failed");
      break;
      }
    • Retrieve a specific session by ID with all activities populated.

      Parameters

      • sessionId: string

        Unique session identifier

      Returns Promise<Session>

      The requested session with complete activity data

      If the session doesn't exist, user lacks access, or request fails

      const session = await client.getSession("session-abc123");
      console.log(`Session has ${session.activities.length} activities`);
    • Retrieves the current processing status of an activity.

      Poll this method to determine when an activity is ready for analysis. Activities must complete video upload and processing before analysis can begin.

      Parameters

      Returns Promise<ActivityProcessingStatus>

      The current processing status

      Network or authentication errors

      const status = await client.getStatus(activity);

      switch (status.type) {
      case "ready":
      console.log("Activity ready for analysis");
      break;
      case "processing":
      console.log("Still processing...");
      break;
      case "uploading":
      console.log(`Uploaded ${status.uploaded}/${status.total} videos`);
      break;
      case "failed":
      console.log("Processing failed");
      break;
      }
    • Initialize the WASM module and client.

      Must be called before using any other methods if autoInit: false was specified in the configuration. Safe to call multiple times.

      Returns Promise<void>

      If WASM initialization fails

      const client = new ModelHealthService({
      apiKey: "your-key",
      autoInit: false
      });
      await client.init();
    • Starts recording a dynamic movement activity.

      After completing calibration steps (camera calibration and neutral pose), use this method to begin recording an activity.

      Parameters

      • activityName: string

        A descriptive name for this activity (e.g., "cmj-test")

      • session: Session

        The session this activity is associated with

      Returns Promise<Activity>

      The newly created activity

      If recording cannot start (session not calibrated, camera issues, etc.)

      // Record a CMJ session
      const activity = await client.record("cmj-2024", session);
      // Subject performs CMJ while cameras record

      // When complete, stop recording
      await client.stopRecording(session);
    • Retrieves all sessions for the account (API key).

      Returns Promise<Session[]>

      An array of Session objects. Returns an empty array if no sessions exist.

      If the request fails due to network issues, authentication problems, or server errors.

      try {
      const sessions = await client.sessionList();
      console.log(`Found ${sessions.length} sessions`);
      for (const session of sessions) {
      console.log(`Session: ${session.id}`);
      }
      } catch (error) {
      console.log(`Failed to fetch sessions: ${error}`);
      }
    • Starts an analysis task for a completed activity.

      The activity must have completed processing (status .ready) before analysis can begin. Use the returned AnalysisTask to poll for completion.

      Parameters

      • analysisType: AnalysisType

        The type of analysis to perform, Gait, Squats, etc

      • activity: Activity

        The activity to analyze

      • session: Session

        The session containing the activity

      Returns Promise<AnalysisTask>

      An analysis task for tracking completion

      Network or authentication errors

      const task = await client.startAnalysis(
      AnalysisType.CounterMovementJump,
      activity,
      session
      );

      // Poll for completion
      const status = await client.getAnalysisStatus(task);
    • Stops recording of a dynamic movement activity in a session.

      Call this method when the subject has completed the movement activity.

      Parameters

      • session: Session

        The session to stop recording in

      Returns Promise<void>

      If the activity cannot be stopped (invalid session ID, already stopped, etc.)

      // After recording is complete
      await client.stopRecording(session);
    • Retrieves all subjects associated with the account.

      Subjects represent individuals being monitored or assessed. Each subject contains demographic information, physical measurements, and categorization tags.

      Returns Promise<Subject[]>

      An array of Subject objects

      If the request fails or authentication has expired

      const subjects = await client.subjectList();
      for (const subject of subjects) {
      console.log(`${subject.name}: ${subject.height ?? 0}cm, ${subject.weight ?? 0}kg`);
      }

      // Filter by tags
      const athletes = subjects.filter(s => s.subjectTags.includes("athlete"));
    • Updates an existing activity.

      Use this method to modify activity properties such as the name. The activity is updated on the server and the updated version is returned.

      Parameters

      • activity: Activity

        The activity to update (with modified properties)

      Returns Promise<Activity>

      The updated activity as stored on the server

      If the update fails or authentication has expired

      let activity = await client.getActivity("abc123");
      // Modify the activity name
      activity.name = "CMJ Baseline Test";
      const updated = await client.updateActivity(activity);
      console.log(`Updated: ${updated.name ?? ""}`);

      Not all activity properties can be modified. Only mutable fields (such as name) will be updated on the server.