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

# Empty or Incomplete Notes After Ending an Ambient Session

> Poll ambient session status until completed before retrieving notes

If you call note or content APIs right after ending an ambient session, you often get empty or incomplete results. Generation is async. Closing the WebSocket and a successful REST end do not mean the note is ready.

Retrieve content only when status is **`completed`**. Stop polling on **`skipped`**, **`failed`**, or **`aborted`**.

## Common causes

* Calling content APIs before status is **`completed`**.
* Treating WebSocket close as "generation finished."
* Skipping **`RU9G`**, socket close, or REST end before you poll.
* Polling forever after **`skipped`**, **`failed`**, or **`aborted`**.

## Fix

<Steps>
  <Step title="Finish the Stream Correctly">
    After the last PCM chunk, send the ambient end marker `{"type":"AUDIO","data":"RU9G"}`, close the WebSocket, then call `POST /api/v1/ambient/session/{ambient_session_id}/end` with `sdp_suki_token` and `sdp_provider_id`. Socket close alone does not complete the session.
  </Step>

  <Step title="Poll GET /status">
    Call `GET /api/v1/ambient/session/{ambient_session_id}/status` with `sdp_suki_token` and `sdp_provider_id` until status is **`completed`**, or stop on **`skipped`**, **`failed`**, or **`aborted`**. See [Wait for Ambient before fetch](/documentation/cookbooks/wait-for-status-before-retrieve).
  </Step>

  <Step title="Stop on Terminal States">
    Return when status is **`completed`**. Stop polling when status is **`skipped`**, **`failed`**, or **`aborted`**. Do not keep calling content APIs expecting a note.
  </Step>

  <Step title="Retrieve Content After Completed">
    Call session content or note content APIs only when status is **`completed`**. Prefer `note_id` with the note content API for the shared clinical note when your flow provides it.
  </Step>
</Steps>

```typescript theme={"theme":{"light":"github-dark","dark":"material-theme-darker"}}
async function waitUntilCompleted(
  ambientSessionId: string,
  pollMs = 2000,
  maxAttempts = 60
): Promise<string> {
  for (let i = 0; i < maxAttempts; i++) {
    const res = await fetch(
      `${BASE_URL}/api/v1/ambient/session/${ambientSessionId}/status`,
      {
        headers: {
          sdp_suki_token: SDP_SUKI_TOKEN,
          sdp_provider_id: SDP_PROVIDER_ID,
        },
      }
    );

    if (!res.ok) {
      throw new Error(`Get ambient session status failed: ${res.status}`);
    }

    const { status } = (await res.json()) as { status: string };
    if (status === "completed") return "completed";
    if (status === "skipped" || status === "failed" || status === "aborted") {
      return status;
    }

    await new Promise((r) => setTimeout(r, pollMs));
  }

  throw new Error("Timed out waiting for session status");
}
```

<Note>
  Sessions shorter than **1 minute** may not contain enough audio for note generation and can be marked as **`skipped`**. Plan your integration to handle that outcome without retrying content retrieval.
</Note>

<Warning>
  Poll status after REST end before you call content APIs. WebSocket close alone does not mean the note is ready.
</Warning>

## Next steps

<Icon icon="file-lines" iconType="solid" /> **[Wait for Ambient before fetch](/documentation/cookbooks/wait-for-status-before-retrieve)** - Poll status until `completed` before content APIs

<Icon icon="file-lines" iconType="solid" /> **[Fetch note by Note ID](/documentation/cookbooks/get-note-content-by-note-id)** - Retrieve the note after status is completed

<Icon icon="file-lines" iconType="solid" /> **[Complete the session after streaming](/documentation/how-to/audio-streaming/websocket-streaming-complete-session)** - Close socket, REST end, then retrieve

<Icon icon="file-lines" iconType="solid" /> **[WebSocket disconnects during ambient streaming](/documentation/troubleshooting/websocket-disconnects-ambient)** - Keep-alives, RU9G, and reconnect rules

<Icon icon="file-lines" iconType="solid" /> **[Content generation is taking too long](/documentation/troubleshooting/content-generation-slow)** - Slow generation vs failed sessions
