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

# Create Ambient Session

> Create an ambient session with `useAmbient`, pass `encounterId` and optional `emrEncounterId`, and obtain `ambientSessionId` and `noteId`

Quick summary

The `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.

Last updated:
October 2026

> [!NOTE]
>
> 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](https://developer.suki.ai/headless-web-sdk/guides/ambient-interoperability.md).

The **`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 under **`PlatformClientProvider`** with a shared **`PlatformClient`** instance.

### Common use cases

**1. 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.isPending`** to detect an active request.
* **`session.isSuccess`** to confirm that the session was created successfully.
* **`session.isError`** to detect request failures.

**2. 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](#code-example) below.

**3. 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](https://developer.suki.ai/headless-web-sdk/guides/handle-ambient-session-conflicts.md) and [Error handling](https://developer.suki.ai/headless-web-sdk/guides/error-handling.md).

## useAmbient hook

### Usage

Call **`useAmbient()`** with no arguments from a component under **`PlatformClientProvider`**. Destructure **`ambientSessionId`**, **`noteId`**, **`session.create`**, and the session status fields.

```tsx theme={"theme":{"light":"one-light","dark":"material-theme-darker"}}
const {
  ambientSessionId,
  noteId, // [!code ++:3] New in v0.3.0
  cancelRemote,
  endRemote,
  session: {
    create,
    error,
    isError,
    isPending,
    isSuccess,
  },
} = useAmbient();
```

### Returns

The hook returns **`ambientSessionId`**, **`noteId`**, **`cancelRemote`**, **`endRemote`**, and a **`session`** object with **`create`**, status flags, and **`error`**. See [What it returns](#what-it-returns).

### How session creation works

1. **Call the hook:** Call **`useAmbient()`** in a component under **`PlatformClientProvider`**.
2. **Create the session:** Call **`session.create({ encounterId, emrEncounterId? })`**. Always pass your encounter id. Pass **`emrEncounterId`** for interoperability.
3. **Get the session and note IDs:** When **`session.isSuccess`** is true, use **`ambientSessionId`** with **`useAmbientSession`**, and store **`noteId`** for note-level Ambient APIs.

The hook provides status flags (`isPending`, `isSuccess`, `isError`) so you can track the creation progress and update your UI accordingly.

![Flowchart: Create ambient session, Request status, Receive SessionId, Pass ambientSessionId, Use ambientSessionId for recording.](https://mintcdn.com/suki-1e08f176/eryJVVKcBRotEMfQ/documentation/assets/diagrams/headless-web-sdk-guides-hooks-ambient-hook-1-light.svg?fit=max\&auto=format\&n=eryJVVKcBRotEMfQ\&q=85\&s=6341b0196d206a734bc1823811f8ddbb)

```mermaid actions={false} theme={"theme":{"light":"one-light","dark":"material-theme-darker"}}
flowchart TD
    A[Create ambient session] --> B{Request status}
    B -->D[Receive SessionId]
    D --> F[Pass ambientSessionId]
    F --> H[Use ambientSessionId for recording]

    style A fill:#FFF394,stroke:#D4A017,color:#000000
    style D fill:#FFF394,stroke:#D4A017,color:#000000
    style F fill:#FFF394,stroke:#D4A017,color:#000000
```

## What it returns

The hook returns the session identifier and status information about the creation request.

### Session identifier

**ambientSessionId** `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`.

**noteId** `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:

**session.isPending** `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.

**session.isSuccess** `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.

**session.isError** `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.

**session.error** `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

**session.create** `(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.

**cancelRemote** `(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.

**endRemote** `(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.

```tsx React expandable theme={"theme":{"light":"one-light","dark":"material-theme-darker"}}
import { useEffect } from 'react';
import { useAmbient } from '@suki-sdk/platform-react';

export const VisitStarter = ({ onSessionReady }) => {
  const {
    ambientSessionId,
    noteId, // [!code ++] New in v0.3.0
    session: { create, isPending, isSuccess, error }
  } = useAmbient();

  // Create the session when component mounts
  useEffect(() => {
    create({
      encounterId: 'your-encounter-id',
      // Pass emrEncounterId to share the note across Ambient products
      emrEncounterId: '6ec3920f-b0b1-499d-a4e9-889bf788e5ab', // [!code ++] New in v0.3.0
    });
  }, [create]);

  // Pass the session ID to parent once creation succeeds
  useEffect(() => {
    if (isSuccess && ambientSessionId) {
      onSessionReady({ ambientSessionId, noteId });
    }
  }, [isSuccess, ambientSessionId, noteId, onSessionReady]);

  // Show loading state while creating
  if (isPending) {
    return <div>Initializing Suki Session...</div>;
  }

  // Show error if creation failed
  if (error) {
    return <div>Error creating session: {error.message}</div>;
  }

  return null;
};
```

**What this example does:**

1. **Initializes the hook** - Gets the `useAmbient` hook and its return values.
2. **Creates session on mount** - Automatically calls `create({ encounterId, emrEncounterId })` when the component loads.
3. **Handles loading state** - Shows a loading message while `isPending` is `true`.
4. **Handles success** - Passes the `ambientSessionId` and `noteId` to the parent component once ready.
5. **Handles errors** - Displays error messages if creation fails.

> [!WARNING]
>
> **Important**: Always wait for `isSuccess` to be `true` before using `ambientSessionId`. Passing an `undefined` session ID to `useAmbientSession` or other hooks will cause errors.

> [!TIP]
>
> Trigger session creation manually (e.g., on button click) instead of automatically on mount by calling `create({ encounterId, emrEncounterId })` when the user performs an action.

## Available tutorials

Ambient
SDK

### [Build a Headless Ambient Recorder](https://developer.suki.ai/documentation/tutorials/headless-ambient-hooks.md)

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

20 min
Intermediate

## Next steps

&#x20;**[Manage ambient session](https://developer.suki.ai/headless-web-sdk/guides/hooks/ambient-session-hook.md)** - Record audio and control the ambient session.

&#x20;**[Ambient interoperability](https://developer.suki.ai/headless-web-sdk/guides/ambient-interoperability.md)** - Share the clinical note across Ambient APIs, Mobile SDK, and Web SDK.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.