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

# End Ambient After Streaming

> Send the RU9G end marker, close the WebSocket, then end the ambient session with REST

**Problem:** You close the WebSocket, but the ambient session never completes and no note is generated.

**Solution:** Send a final `AUDIO` frame with `"data": "RU9G"` (Base64 of ASCII `EOF`), close the socket, then `POST /api/v1/ambient/session/{ambient_session_id}/end`. Closing the socket alone is not enough.

<Note>
  This cookbook assumes you already have your Partner ID, authentication tokens, and an active ambient session with a WebSocket stream open.
</Note>

<Tabs>
  <Tab title="TypeScript">
    ```typescript theme={"theme":{"light":"github-dark","dark":"material-theme-darker"}}
    // After the last PCM chunk on the ambient WebSocket:
    ws.send(JSON.stringify({ type: "AUDIO", data: "RU9G" }));
    ws.close();

    const endRes = await fetch(
      `https://sdp.suki.ai/api/v1/ambient/session/${ambientSessionId}/end`,
      {
        method: "POST",
        headers: {
          sdp_suki_token: sdpSukiToken,
          sdp_provider_id: sdpProviderId,
        },
      }
    );
    if (!endRes.ok) {
      throw new Error(`End ambient session failed: ${endRes.status}`);
    }

    // Then poll status before content APIs
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={"theme":{"light":"github-dark","dark":"material-theme-darker"}}
    import json
    import requests

    # After the last PCM chunk on the ambient WebSocket:
    ws.send(json.dumps({"type": "AUDIO", "data": "RU9G"}))
    ws.close()

    end = requests.post(
        f"https://sdp.suki.ai/api/v1/ambient/session/{ambient_session_id}/end",
        headers={
            "sdp_suki_token": sdp_suki_token,
            "sdp_provider_id": sdp_provider_id,
        },
    )
    end.raise_for_status()

    # Then poll status before content APIs
    ```
  </Tab>
</Tabs>

## Common mistakes

* Close the WebSocket without sending `RU9G`.
* Send Dictation-style `AUDIO_END` on the ambient `/ws/stream` endpoint.
* Treat WebSocket close alone as session complete. You still need REST end, then status polling.

## Other cookbooks

<div className="cookbook-hub-wrap">
  <div className="hp-io-method-grid tut-hub-card-grid" data-cookbook-related-grid>
    <a className="hp-io-method-card tut-hub-method-card" href="/documentation/cookbooks/wait-for-status-before-retrieve">
      <div className="tut-hub-card-media tut-hub-card-media--blue" aria-hidden="true" />

      <div className="hp-io-method-card-body">
        <div className="tut-hub-card-badges">
          <span className="hp-wn-badge hp-wn-badge-new">Ambient</span>
          <span className="hp-wn-badge cookbook-hub-badge-surface cookbook-hub-badge-surface--api">API</span>
        </div>

        <h3 className="hp-io-method-card-title">Poll Session Status Before Fetching Content</h3>

        <p className="hp-io-method-card-desc cookbook-hub-card-desc">
          Poll until status is completed.
        </p>

        <div className="hp-io-method-card-meta tut-hub-card-foot" aria-label="5 min">
          <div className="tut-hub-card-foot-meta">
            <span className="hp-io-method-card-meta-time">5 min</span>
          </div>
        </div>
      </div>
    </a>

    <a className="hp-io-method-card tut-hub-method-card" href="/documentation/cookbooks/browser-websocket-auth">
      <div className="tut-hub-card-media" aria-hidden="true" />

      <div className="hp-io-method-card-body">
        <div className="tut-hub-card-badges">
          <span className="hp-wn-badge hp-wn-badge-new">Ambient</span>
          <span className="hp-wn-badge cookbook-hub-badge-surface cookbook-hub-badge-surface--api">API</span>
        </div>

        <h3 className="hp-io-method-card-title">Authenticate Browser WebSocket Handshake</h3>

        <p className="hp-io-method-card-desc cookbook-hub-card-desc">
          Auth browser WebSocket with protocols.
        </p>

        <div className="hp-io-method-card-meta tut-hub-card-foot" aria-label="5 min">
          <div className="tut-hub-card-foot-meta">
            <span className="hp-io-method-card-meta-time">5 min</span>
          </div>
        </div>
      </div>
    </a>
  </div>
</div>
