Documentation Index
Fetch the complete documentation index at: https://developer.suki.ai/llms.txt
Use this file to discover all available pages before exploring further.
Quick summary
Use this guide to implement recommended patterns for pausing and submitting sessions with the
useAmbientSession hook. By following these patterns, you ensure that the Suki handles audio data correctly and you avoid conflicts with the Headless Web SDK.useAmbientSession hook provides the pause(), setSessionContext(), submit(), and cancel() methods. The Headless Web SDK manages buffering, queuing, and upload orchestration for you.
If you add custom recovery logic, you might accidentally discard valid audio or call methods in an incorrect order. Follow this guide to implement recommended patterns for pausing and submitting sessions with the useAmbientSession hook. By following these patterns, you ensure that the Suki handles audio data correctly and you avoid conflicts with the Headless Web SDK.
Built-in behavior
The Headless Web SDK manages buffering, queuing, and upload orchestration for you. You do not need to re-implement these features in your application:- Offline and network drops - When the session is offline, the Headless Web SDK persists audio (for example in
IndexedDB) and manages the upload queue. For details, refer to Network transitions and Offline mode for more information. - Finalization with
submit()- Usesubmit()to complete the session and send captured audio to the Suki backend server for processing. - Recoverable pause errors - A failed
pause()call does not always mean session data or buffered audio is lost. Refer to Pausing a session (PauseSessionFailed) in the error handling guide for more information. This guide covers how to handle these errors.
Common mistakes to avoid
The following are common mistakes to avoid when using theuseAmbientSession hook.
Retrying pause() from stale state
Retrying pause() from stale state
sessionStatus reflects the state of the last React render. If you call pause() again because the status has not updated yet, the API may return an InvalidSessionState error.Instead: Call pause() once. If the request fails, log a warning and stop. Do not use sessionStatus as an immediate source of truth right after an await pause() call.Using cancel() as a fallback
Using cancel() as a fallback
The
cancel() method is only for when a user explicitly abandons an encounter. It tears down the session and clears locally captured audio.Instead: Do not call cancel() in a catch block to recover from non-abandon errors. That pattern can lead to lost submissions during offline recording.Hiding errors from destructive actions
Hiding errors from destructive actions
If you use a destructive fallback like
cancel() and ignore the failure, your UI may drift away from the actual SDK session state.Instead: If you perform a destructive action, always surface failures to the user or your logging pipeline.Recommended flow
Follow this flow so your integration stays aligned with the Headless Web SDK:Set context (best effort)
Use
setSessionContext() when you have fresh visit metadata. You can still call submit() when your product rules allow it, even if this step fails.Code example
This example wrapspause, setSessionContext, and submit in a helper hook. Types follow Session context and UseAmbientSessionReturn. Swap in your own sessionContext, shouldSkipSubmit, and callbacks.
React
useAmbientSession into the helper:
React