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.useAmbient hook allows you to create an ambient session on Suki’s servers. It returns an ambientSessionId and session.create() with status flags so you know when it is safe to hand that id to useAmbientSession for recording.
Configuration
Run the hook underPlatformClientProvider with a shared PlatformClient instance.
Common use cases
Provision an ambient session
Create an ambient session when a visit begins or when your application is ready to start the workflow. Call
session.create() to send the request to the Suki backend. While the request is in progress, monitor the session state using:session.isPendingto detect an active requestsession.isSuccessto confirm that the session was created successfullysession.isErrorto detect request failures
Pass the ambient session to downstream workflows
After the session is created successfully, read the returned
ambientSessionId and pass it to useAmbientSession to continue the workflow.Only access ambientSessionId after session.isSuccess is true. Do not pass an undefined or incomplete session ID. For more information, refer to the warning in Code example below.Handle session creation errors
If session creation fails,
session.isError is set to true. Read session.error to inspect the failure and implement retry or user-facing error handling logic.For implementation details, refer to Error handling.useAmbient hook
Usage
CalluseAmbient() with no arguments from a component under PlatformClientProvider. Destructure ambientSessionId, session.create, and the session status fields.
Returns
The hook returnsambientSessionId and a session object with create(), status flags, and error, documented under What it returns.
How session creation works
- 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: When creation succeeds, use
ambientSessionIdfor recording (typically withuseAmbientSession).
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. 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