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

# Upload Ambient Pre-Recorded Audio

> Create an Ambient session with input_type audio_file, mint a presigned URL, and PUT one WAV without calling end session

# Upload Ambient Pre-Recorded Audio

Create an Ambient session with `input_type` `audio_file`, mint a presigned upload URL, PUT one WAV, and skip end session. Processing starts when the upload succeeds.

## Problem

Partners often already have a WAV recording from telephony or a telehealth archive. They then try to stream that file live on `/ws/stream`, or they call end session after upload. Those steps belong to live `stream` sessions, not `audio_file` input.

For Ambient `audio_file` sessions, create with that `input_type`, mint the upload URL, PUT one WAV with both signed headers, and skip end session. Processing starts when the PUT succeeds.

## Architecture

![Flowchart: Create audio\_file, GET file-uploadurl, PUT WAV, Poll status.](https://mintcdn.com/suki-1e08f176/Srzj30gTyAYo6M-z/documentation/assets/diagrams/cookbooks-upload-prerecorded-ambient-audio-1-light.svg?fit=max\&auto=format\&n=Srzj30gTyAYo6M-z\&q=85\&s=46520f419aba3a26ab4342679b67e919)

```mermaid actions={false} theme={"theme":{"light":"one-light","dark":"material-theme-darker"}}
%%{init: {'theme':'base', 'themeVariables': { 'primaryColor':'#FFFBDE','primaryTextColor':'#1C1C1C','primaryBorderColor':'#FFD147','lineColor':'#6F5410','secondaryColor':'#FFFDF5','tertiaryColor':'#FFEB94','fontSize':'13px'}}}%%
flowchart LR
  A[Create audio_file] --> B[GET file-uploadurl] --> C[PUT WAV] --> D[Poll status]
```

## Prerequisites

> [!TIP]
>
> Completed [Partner onboarding](https://developer.suki.ai/documentation/get-started/partner-onboarding.md) and can obtain `sdp_suki_token` from Login.

> [!TIP]
>
> One WAV file, at most 500 MB.

> [!TIP]
>
> `sdp_suki_token` and `sdp_provider_id` headers ready for REST calls.

## Solution

> [card] Before
>
> Have Partner credentials and a WAV recording.

> [card] This Recipe
>
> Create with `audio_file`, mint the URL, PUT one WAV, skip end session.

> [card] Next
>
> [Wait for Ambient before Fetch](https://developer.suki.ai/documentation/cookbooks/wait-for-status-before-retrieve.md)

Create the session with `input_type: "audio_file"`, seed visit context when your product needs it, mint the presigned URL, then PUT one WAV. Required PUT headers are `Content-Type: audio/wave` and `x-goog-if-generation-match: 0`. Do not call end session. Full Ambient staging scripts live in [Upload pre-recorded audio](https://developer.suki.ai/documentation/how-to/ambient-clinical-notes/upload-prerecorded-audio-ambient.md).

> [tab] TypeScript
>
> ```typescript theme={"theme":{"light":"one-light","dark":"material-theme-darker"}}
> // upload-prerecorded-ambient-audio.ts
> // Flow: create (audio_file) → GET file-uploadurl → PUT WAV → poll status (related cookbook)
> import fs from "node:fs";
>
> const BASE_URL = process.env.SUKI_BASE_URL ?? "https://sdp.suki.ai";
> const SDP_SUKI_TOKEN = process.env.SDP_SUKI_TOKEN!; // from Login (suki_token)
> const SDP_PROVIDER_ID = process.env.SDP_PROVIDER_ID!; // required for Bearer / Single Auth
> const AUDIO_PATH = process.env.AUDIO_PATH ?? "visit.wav";
>
> function restHeaders(): Record<string, string> {
>   return {
>     sdp_suki_token: SDP_SUKI_TOKEN,
>     sdp_provider_id: SDP_PROVIDER_ID,
>     "Content-Type": "application/json",
>   };
> }
>
> async function createAudioFileSession(): Promise<string> {
>   const res = await fetch(`${BASE_URL}/api/v1/ambient/session/create`, {
>     method: "POST",
>     headers: restHeaders(),
>     body: JSON.stringify({ input_type: "audio_file" }),
>   });
>   if (res.status !== 201) {
>     throw new Error(`Create ambient session failed: ${res.status}`);
>   }
>   const { ambient_session_id } = (await res.json()) as {
>     ambient_session_id: string;
>   };
>   return ambient_session_id;
> }
>
> async function mintUploadUrl(ambientSessionId: string): Promise<string> {
>   const res = await fetch(
>     `${BASE_URL}/api/v1/ambient/audio/file-uploadurl/${ambientSessionId}`,
>     { headers: restHeaders() }
>   );
>   if (!res.ok) {
>     throw new Error(`Mint upload URL failed: ${res.status}`);
>   }
>   const { presigned_url_response } = (await res.json()) as {
>     presigned_url_response: { url: string };
>   };
>   return presigned_url_response.url;
> }
>
> async function putWav(uploadUrl: string, audioPath: string): Promise<void> {
>   const res = await fetch(uploadUrl, {
>     method: "PUT",
>     headers: {
>       "Content-Type": "audio/wave",
>       "x-goog-if-generation-match": "0",
>     },
>     body: fs.readFileSync(audioPath),
>   });
>   if (!res.ok) {
>     throw new Error(`Upload failed: ${res.status} ${await res.text()}`);
>   }
> }
>
> const ambientSessionId = await createAudioFileSession();
> const uploadUrl = await mintUploadUrl(ambientSessionId);
> await putWav(uploadUrl, AUDIO_PATH);
> console.log("Upload complete. Do not call end session.", ambientSessionId);
> // Next: poll status → retrieve content (see related cookbooks).
> ```

> [tab] Python
>
> ```python theme={"theme":{"light":"one-light","dark":"material-theme-darker"}}
> # upload_prerecorded_ambient_audio.py
> # Flow: create (audio_file) → GET file-uploadurl → PUT WAV → poll status (related cookbook)
> # pip install requests
>
> import os
>
> import requests
>
> BASE_URL = os.environ.get("SUKI_BASE_URL", "https://sdp.suki.ai")
> SDP_SUKI_TOKEN = os.environ["SDP_SUKI_TOKEN"]  # from Login (suki_token)
> SDP_PROVIDER_ID = os.environ["SDP_PROVIDER_ID"]  # required for Bearer / Single Auth
> AUDIO_PATH = os.environ.get("AUDIO_PATH", "visit.wav")
>
>
> def rest_headers() -> dict[str, str]:
>     return {
>         "sdp_suki_token": SDP_SUKI_TOKEN,
>         "sdp_provider_id": SDP_PROVIDER_ID,
>         "Content-Type": "application/json",
>     }
>
>
> def create_audio_file_session() -> str:
>     res = requests.post(
>         f"{BASE_URL}/api/v1/ambient/session/create",
>         headers=rest_headers(),
>         json={"input_type": "audio_file"},
>         timeout=60,
>     )
>     if res.status_code != 201:
>         raise RuntimeError(f"Create ambient session failed: {res.status_code}")
>     return res.json()["ambient_session_id"]
>
>
> def mint_upload_url(ambient_session_id: str) -> str:
>     res = requests.get(
>         f"{BASE_URL}/api/v1/ambient/audio/file-uploadurl/{ambient_session_id}",
>         headers=rest_headers(),
>         timeout=60,
>     )
>     res.raise_for_status()
>     return res.json()["presigned_url_response"]["url"]
>
>
> def put_wav(upload_url: str, audio_path: str) -> None:
>     with open(audio_path, "rb") as audio_file:
>         res = requests.put(
>             upload_url,
>             data=audio_file,
>             headers={
>                 "Content-Type": "audio/wave",
>                 "x-goog-if-generation-match": "0",
>             },
>             timeout=300,
>         )
>     res.raise_for_status()
>
>
> ambient_session_id = create_audio_file_session()
> upload_url = mint_upload_url(ambient_session_id)
> put_wav(upload_url, AUDIO_PATH)
> print("Upload complete. Do not call end session.", ambient_session_id)
> # Next: poll status → retrieve content (see related cookbooks).
> ```

**1. Create the Ambient session with audio\_file input**

Call create with `input_type` set to `audio_file`. Store `ambient_session_id`. See [Create ambient session](https://developer.suki.ai/api-reference/ambient-sessions/create.md).

**2. Seed visit context when needed**

Send patient, visit, specialty, and section context the same way you do for a live stream session.

**3. Mint the upload URL and PUT one WAV**

`GET /api/v1/ambient/audio/file-uploadurl/{ambient_session_id}`, then PUT the WAV with `Content-Type: audio/wave` and `x-goog-if-generation-match: 0`. Do not call end session. See [Get file upload URL](https://developer.suki.ai/api-reference/ambient-sessions/file-uploadurl.md).

**4. Poll before retrieving content**

Poll session status until `completed`, then call content APIs. Use [Wait for Ambient before Fetch](https://developer.suki.ai/documentation/cookbooks/wait-for-status-before-retrieve.md) next.

## Try it

> [card]
>
> * **Create returns an audio\_file session**
>
>   Create with `input_type: "audio_file"` returns HTTP 201 and an `ambient_session_id`. Do not open `/ws/stream` for this path.
>
> * **PUT starts processing**
>
>   A successful WAV upload starts generation. Do not call REST end after the PUT.
>
> * **Both signed headers are required**
>
>   The PUT must send `Content-Type: audio/wave` and `x-goog-if-generation-match: 0`. Missing either header fails the upload.

## Common mistakes

> [!WARNING]
>
> * Stream the WAV on `/ws/stream` or call end session after upload.
> * Omit `Content-Type: audio/wave` or `x-goog-if-generation-match: 0` on the PUT.
> * Call content APIs immediately after upload without polling status first.

## Related cookbooks

Ambient
API

### [Submit Ambient Finished Transcript](https://developer.suki.ai/documentation/cookbooks/submit-finished-transcript-ambient.md)

Create with transcript, submit text once.

10 min

Ambient
API

### [Wait for Ambient before Fetch](https://developer.suki.ai/documentation/cookbooks/wait-for-status-before-retrieve.md)

Poll until status is completed.

5 min

Run This Recipe

[Open Full Tutorial](https://developer.suki.ai/documentation/tutorials/ambient-websocket-code-example.md)
[View API Reference](https://developer.suki.ai/api-reference/ambient-sessions/file-uploadurl.md)

Step-by-step tutorial and API reference for this workflow.


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