Skip to main content
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 Suki handles audio data correctly and you avoid conflicts with the Headless Web SDK.
The 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 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() - Use submit() 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 the useAmbientSession hook.
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.
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.
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.
Follow this flow so your integration stays aligned with the Headless Web SDK:
1

Pause Once

Call pause() a single time. On failure, log the error and stop.
2

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.
3

Submit to Finalize

Call submit() to upload queued chunks and complete the session.
4

Reserve Cancel() for Discard

Only call cancel() when the user confirms they want to abandon the session.

Code example

This example wraps pause, setSessionContext, and submit in a helper hook. Types follow Session context and UseAmbientSessionReturn. Swap in your own sessionContext, shouldSkipSubmit, and callbacks.
React
Pass the methods from useAmbientSession into the helper:
React

Next steps

Learn how to map errors to fixes in the Error handling guide. Understand offline sessions in Offline mode.
Last modified on August 13, 2026