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

# Clear a Remote Session Conflict

> End the blocking ambient session for an EMR encounter, then retry create

**Problem:** Create returns HTTP **409** (`session_in_progress`) because another modality already has an active session for the same `emr_encounter_id`.

**Solution:** Read `ambient_session_id` from the conflict response, [End session](/api-reference/ambient-sessions/end), wait **1 second**, then retry create.

<Note>
  This cookbook assumes you already have your Partner ID, authentication tokens, and the other prerequisites for Ambient APIs.
</Note>

<Tabs>
  <Tab title="TypeScript">
    ```typescript theme={"theme":{"light":"github-dark","dark":"material-theme-darker"}}
    const headers = {
      "Content-Type": "application/json",
      sdp_suki_token: sdpSukiToken,
      sdp_provider_id: sdpProviderId,
    };

    async function createOrResolveConflict(emrEncounterId: string) {
      const createRes = await fetch("https://sdp.suki.ai/api/v1/ambient/session/create", {
        method: "POST",
        headers,
        body: JSON.stringify({ emr_encounter_id: emrEncounterId }),
      });

      if (createRes.ok) {
        return createRes.json();
      }

      const err = await createRes.json().catch(() => ({}));
      const message = String(err?.message || "");
      const isConflict =
        createRes.status === 409 || message.includes("session_in_progress");

      if (!isConflict) {
        throw new Error(`Create ambient session failed: ${createRes.status}`);
      }

      const blockingSessionId = err.ambient_session_id;
      if (!blockingSessionId) {
        throw new Error(
          "Conflict returned without ambient_session_id. End the active session from the owning modality, then retry."
        );
      }

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

      await new Promise((r) => setTimeout(r, 1000));

      const retry = await fetch("https://sdp.suki.ai/api/v1/ambient/session/create", {
        method: "POST",
        headers,
        body: JSON.stringify({ emr_encounter_id: emrEncounterId }),
      });
      if (!retry.ok) {
        throw new Error(`Retry create failed: ${retry.status}`);
      }
      return retry.json();
    }
    ```
  </Tab>

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

    headers = {
        "Content-Type": "application/json",
        "sdp_suki_token": sdp_suki_token,
        "sdp_provider_id": sdp_provider_id,
    }

    def create_or_resolve_conflict(emr_encounter_id: str):
        create = requests.post(
            "https://sdp.suki.ai/api/v1/ambient/session/create",
            headers=headers,
            json={"emr_encounter_id": emr_encounter_id},
        )
        if create.ok:
            return create.json()

        try:
            err = create.json()
        except ValueError:
            err = {}

        message = str(err.get("message") or "")
        is_conflict = create.status_code == 409 or "session_in_progress" in message
        if not is_conflict:
            create.raise_for_status()

        blocking = err.get("ambient_session_id")
        if not blocking:
            raise RuntimeError(
                "Conflict returned without ambient_session_id. "
                "End the active session from the owning modality, then retry."
            )

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

        retry = requests.post(
            "https://sdp.suki.ai/api/v1/ambient/session/create",
            headers=headers,
            json={"emr_encounter_id": emr_encounter_id},
        )
        retry.raise_for_status()
        return retry.json()
    ```
  </Tab>
</Tabs>

## Common mistakes

* Confirm the blocking id before you end. Wait **1 second** before retry.
* If the body omits `ambient_session_id`, end from the owning modality, then retry.

## 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/pass-emr-encounter-id">
      <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">Share One Note Across Products</h3>

        <p className="hp-io-method-card-desc cookbook-hub-card-desc">
          Share one note with emr\_encounter\_id.
        </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/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>
  </div>
</div>
