Quick summary
The
Pass optional
useAmbient hook creates a new ambient session on Suki’s servers. Call session.create({ encounterId }) with your encounter id. You get back an ambientSessionId for recording and a noteId for the shared clinical note.Pass optional
emrEncounterId to make the note interoperable across Ambient products. Use the status flags (isPending, isSuccess, isError) to track creation. When isSuccess is true, pass ambientSessionId to useAmbientSession to start recording.To share the clinical note across Ambient APIs, Mobile SDK, Web SDK, and Headless Web SDK, pass
emrEncounterId on create. For the full workflow, refer to Ambient interoperability.useAmbient hook creates an ambient session on Suki’s servers. It returns ambientSessionId, noteId, session.create, cancelRemote, endRemote, and status flags. Pass a required encounterId when you call create. Wait for success before you hand the id to useAmbientSession.
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 app is ready. Call
session.create({ encounterId: "your-encounter-id" }). encounterId is required. Optional fields include emrEncounterId (required for interoperability) and multilingual. While the request runs, use:session.isPendingto detect an active request.session.isSuccessto confirm that the session was created successfully.session.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. Store noteId when you need note-level Ambient APIs.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.When another product already holds the active session for the same EMR encounter, the error reason is sessionAlreadyExists. Use cancelRemote or endRemote, then retry create. Refer to Handle ambient session conflicts and Error handling.useAmbient hook
Usage
CalluseAmbient() with no arguments from a component under PlatformClientProvider. Destructure ambientSessionId, noteId, session.create, and the session status fields.
Returns
The hook returnsambientSessionId, noteId, cancelRemote, endRemote, and a session object with create, status flags, and error. See What it returns.
How session creation works
- Call the hook: Call
useAmbient()in a component underPlatformClientProvider. - Create the session: Call
session.create({ encounterId, emrEncounterId? }). Always pass your encounter id. PassemrEncounterIdfor interoperability. - Get the session and note IDs: When
session.isSuccessis true, useambientSessionIdwithuseAmbientSession, and storenoteIdfor note-level Ambient APIs.
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
string | null
The unique identifier for your ambient session. This value is
null until the session is successfully created. Once isSuccess is true, you’ll have a valid session ID to use with other hooks like useAmbientSession.string | null
The shared clinical note identifier returned on successful create. Maps to Ambient API
note_id. Store this value for note-level Ambient APIs. This value is null until create succeeds.Status flags
Use these boolean flags to control your UI and handle the creation lifecycle:boolean
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.boolean
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.boolean
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.Error | null
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 when there’s no error. For remote session conflicts, check reason === "sessionAlreadyExists" and read additionalProperties.blockingSessionId.Actions
(params: { encounterId: string; emrEncounterId?: string; multilingual?: boolean }) => Promise<{ ambientSessionId: string; noteId: string }>
Creates a new ambient session.
encounterId is required. Optional: emrEncounterId (required for interoperability), multilingual. Status flags update while the request runs. Call this after sign-in, for example on mount or when the user starts a visit.(params: { ambientSessionId: string }) => Promise<void>
Cancels a remote ambient session that is blocking create in another Suki product. Pass the
blockingSessionId from a sessionAlreadyExists error. Available before a local session exists.(params: { ambientSessionId: string }) => Promise<void>
Ends a remote ambient session that is blocking create in another Suki product so captured audio can be processed. Pass the
blockingSessionId from a sessionAlreadyExists error.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({ encounterId, emrEncounterId })when the component loads. - Handles loading state - Shows a loading message while
isPendingistrue. - Handles success - Passes the
ambientSessionIdandnoteIdto the parent component once ready. - Handles errors - Displays error messages if creation fails.