Quick Summary
The
The hook provides status flags (
useAmbient hook creates a new ambient session container on Suki’s servers. You call session.create() to get a unique ambientSessionId that identifies your session.The hook provides status flags (
isPending, isSuccess, isError) so you can track the creation progress and update your UI accordingly. Once you have the ambientSessionId, you can use it with useAmbientSession to start recording.Overview
TheuseAmbient hook creates a new ambient session in Suki’s backend. Think of it as the first step in your ambient documentation workflow.
What it does:
Before you can record audio or manage a session, you need to create a session container on Suki’s servers. This hook handles that creation process and gives you a unique ambientSessionId that identifies your session.
How It Works
The hook works in three simple steps:- Call the hook - Initialize
useAmbient()in your component - Create the session - Call
session.create()to request a new session from Suki’s backend - Get the session ID - Once successful, use the
ambientSessionIdto proceed with recording
isPending, isSuccess, isError) so you can track the creation progress and update your UI accordingly.
What It Returns
The hook returns the session identifier and status information about the creation request.Session Identifier
The unique identifier for your ambient session. This value is
undefined until the session is successfully created. Once isSuccess is true, you’ll have a valid session ID to use with other hooks like useAmbientSession.Status Flags
Use these boolean flags to control your UI and handle the creation lifecycle:Check this flag to show a loading state in your UI. When
true, display a loading spinner, disable buttons, or show a “Creating session.” message. The hook sets this to true while creating the session.Check this flag to proceed with recording. When
true, the session is ready and ambientSessionId contains a valid session ID. Show your recording controls or pass the session ID to the next step in your workflow.Check this flag to display error messages in your UI. When
true, show an error message to the user using details from session.error. You might want to offer a retry option or redirect to an error page.Use this to display specific error information to users. When
session.isError is true, read this object to show error messages, error codes, or troubleshooting information in your UI. It remains null or undefined when there’s no error.Actions
Call this function to create a new ambient session. The function sends a request to Suki’s backend and updates all status flags automatically. You can call it when a component mounts, when a user clicks a button, or at any point in your workflow.
Code Example
This example shows how to create a session when a user starts a patient visit. The session is created automatically when the component mounts, and the session ID is passed to the parent component once ready.React
- Initializes the hook - Gets the
useAmbienthook and its return values - Creates session on mount - Automatically calls
create()when the component loads - Handles loading state - Shows a loading message while
isPendingistrue - Handles success - Passes the
ambientSessionIdto the parent component once ready - Handles errors - Displays error messages if creation fails