Skip to main content
UpdatedThe useAmbientSession hook now returns a sessionType property. This helps you determine whether the session is an online or offline session.
Quick summary
The useAmbientSession hook controls your audio recording workflow. Use it after creating a session with useAmbient to manage recording, pausing, and submitting audio.

The hook provides methods to start, pause, resume, cancel, and submit recordings. It returns session status so you can update your UI and provides real-time audio data through callbacks for building visualizations.
The useAmbientSession hook allows you to control the ambient recording workflow after you have an ambientSessionId. It exposes start, pause, resume, cancel, and submit, optional setSessionContext, cancelRemote, endRemote, session status, sessionType (online or offline), optional onSessionTerminatedByPeer, and optional real-time audio chunks for visualizations.

Configuration

Pass the ambientSessionId you received from useAmbient after session.isSuccess is true (refer to Create ambient session). Run the hook under PlatformClientProvider. Refer to Platform client and provider for more information.

Common use cases

Control the Recording Lifecycle

Use the recording control methods to match the behavior of your application’s recording experience:
  • start() to begin recording.
  • pause() to temporarily stop audio capture.
  • resume() to continue a paused recording.
  • cancel() to discard the current session.
  • submit() to finalize and submit the recording for processing.

Attach Clinical Context to a Session

Use setSessionContext() to associate patient, provider, and visit metadata with the active session.Call setSessionContext() after start() and before submit() to ensure the metadata is included with the session. For supported fields and examples, refer to Session context below.

Support Online and Offline Session Flows

Read sessionType to determine how the session is running:
  • "online" for real-time workflows.
  • "offline" for deferred or asynchronous processing workflows.
Use this value to conditionally render UI, messaging, or workflow behavior.

Process Audio Waveform Data

Use onAudioChunkAvailable to receive streamed audio chunks during recording. Audio data is returned as batched Int16Array chunks.Optionally configure config.audioBatchSize to control the batch size and frequency of audio chunk delivery.

Build Responsive Session Status UI

Use the returned session state values to drive UI behavior throughout the recording workflow:
  • sessionStatus for the server-side session lifecycle (for example created, submitted, completed).
  • sessionType for online versus offline messaging.
Keep a local UI phase (for example idle, recording, paused) for Start, Pause, and Resume. Do not use sessionStatus alone for recording versus paused.

Resolve Remote Session Conflicts

Use cancelRemote or endRemote with the blocking session id from a sessionAlreadyExists create error when another Suki product holds the active ambient session. Then retry create. Refer to Handle ambient session conflicts.

Handle Peer Session Termination

Pass onSessionTerminatedByPeer so your UI can clear recording controls when another product cancels or ends the live session. Update UI only. Do not call local cancel, submit, or remote clear APIs for that direction.

useAmbientSession hook

Usage

Call useAmbientSession with an object that includes ambientSessionId and optional config, onAudioChunkAvailable, and onSessionTerminatedByPeer.

Returns

The hook returns control methods, session status, sessionType, and related fields. Parameter and return shapes are documented under Configuration and What it returns.

How recording works

  1. Pass the session ID: Provide the ambientSessionId from useAmbient.
  2. Configure options: Optionally set config.audioBatchSize and onAudioChunkAvailable for real-time audio batches.
  3. Use the controls: Call start, pause, resume, cancel, and submit to move through the lifecycle your UI needs.

Configuration

Configure the hook with these parameters:
string
required
Pass the unique session identifier you received from the useAmbient hook. This links the recording to the session you created.
number
Optional: Configure the audio batch size for the onAudioChunkAvailable callback.
function (audioChunk: Array<Int16Array>) => void
Optional: Provide a callback function that receives audio chunks as they become available. The SDK calls this function whenever a batch of audio data is ready. Use this to draw real-time waveforms, visualizers, or other audio visualizations in your UI.
function (payload: { sessionId: string; reason: string }) => void
Optional: Called after another Suki product cancels or ends the live session. The SDK already stops the microphone, deletes local audio metadata, and resets the stream. Update your UI only. Do not call cancel(), submit(), cancelRemote(), or endRemote() for this direction.

What it returns

The hook returns control methods and status information you use to manage recording and update your UI.

Actions (methods)

Use these methods to control the recording workflow:
function: () => Promise<void>
Call this to begin recording audio. Call this when the user clicks a “Start Recording” button.
function: () => Promise<void>
Call this to pause recording temporarily. Resume later with resume(). Call this when the user clicks a “Pause” button.
function: () => Promise<void>
Call this to resume a paused recording. Call this when the user clicks a “Resume” button.
function: () => Promise<void>
Call this to stop recording and cancel the session. Call this when the user clicks a “Cancel” or “Discard” button.
function: () => Promise<void>
Call this to finish recording and submit the session for note generation. Call this when the user clicks a “Finish” or “Submit” button.
function: (context: Omit<SessionContext, 'ambientSessionId'>) => Promise<void>
Call this to send patient, provider, and visit metadata to Suki. The function sends context information that helps Suki generate more accurate clinical notes. Call this after start() but before submit() for best results. On success the promise resolves with no return value. On failure it throws.
function: (params: { ambientSessionId: string }) => Promise<void>
Cancels a remote ambient session that is blocking create in another modality. Pass the blocking session id from a sessionAlreadyExists create error, not the hook’s local ambientSessionId.
function: (params: { ambientSessionId: string }) => Promise<void>
Ends a remote ambient session that is blocking create in another modality so captured audio can be processed. Pass the blocking session id from a sessionAlreadyExists create error.

State (data)

Use these values to control your UI and show the current session state:
AmbientSessionStatus | null | undefined
Server-side session lifecycle. Common values:
  • "created" (ready to start)
  • "submitted" (recording finished, processing)
  • "completed" (note generated), and
  • "cancelled"
Can be null or undefined before the store has session state. For the full union, refer to AmbientSessionStatus. Do not use this field alone for recording versus paused UI.
'online' | 'offline' | null
Whether the session is online or offline. null until the SDK reports a session type.

Session context

The setSessionContext method lets you send patient, provider, and visit information to Suki. This context helps Suki’s AI generate more accurate and relevant clinical notes.

What is session context?

Session context is metadata about the patient visit that improves note quality. Include:
  • Patient details: Date of birth, sex, optional patient_id, and optional structured name.
  • Provider information: Specialty, role.
  • Visit information: Visit type, encounter type, reason for visit, chief complaint.
  • Clinical sections: LOINC codes for specific sections you want in the note.
  • Diagnoses: Pre-existing or current diagnoses with codes and descriptions.

When to use it

Call setSessionContext after calling start() but before calling submit(). Providing context early helps the AI understand the clinical scenario and generate better notes.

Session context structure

  • An empty name object is dropped and is not sent.
  • Name values are passed through as provided. The Headless Web SDK does not force normalization.
  • Web SDK handoff: If you capture audio in Headless but the clinician reviews the note in the Web SDK, send patient_id and structured name with setSessionContext. Suki uses those fields to fill in the patient header in the Web SDK. See Seed patient context for Web SDK handoff.

Success and errors

On success, setSessionContext resolves with no return value (Promise<void>). If an error occurs, it throws a ContextUpdateFailed error. See the Error handling guide for details.

Code example

This example shows how to build a recording interface with Start, Pause, Resume, and Submit controls. The UI updates based on sessionStatus to show the appropriate buttons at each stage.
React
Always call setSessionContext to provide patient and encounter details. This context helps the AI understand the clinical scenario and generates significantly higher quality clinical notes.

Available tutorials

Headless Web SDK

Build a Headless Ambient Recorder

Use Headless hooks to sign in, create an ambient session, and control recording in a custom React UI.

20 minIntermediate

Next steps

Learn production pause and submit patterns in Session integration patterns. Learn how to handle errors in the Error handling guide. Refer to Handle ambient session conflicts and Read shared ambient notes for remote conflict handling, remote session end handling, and shared note reads.
Last modified on September 2, 2026