Skip to main content
What you will build

20 min | Intermediate

  • Login and create an ambient session
  • Stream raw PCM audio over WebSocket
  • End the session and poll for note results
  • Handle common API errors
Using an AI coding tool?Copy the following prompt to add the Suki developer documentation as a skill and MCP server to your tool for better AI-assisted coding during the integration process. For all AI options (contextual menu, llms.txt, and skill.md), refer to AI-optimized documentation.

Install the Suki developer docs as a skill to get context on Suki's developer tools, APIs, and SDKs. Add the MCP server for documentation search.

Open in Cursor
In this tutorial, you build an end-to-end ambient streaming client. You authenticate, create a session, add initial context, stream PCM audio over a WebSocket connection, end the session, and retrieve the results. Examples are provided in Python, TypeScript, and Go coding languages. By the end of this tutorial, you’ll have a working client that connects to the production endpoints https://sdp.suki.ai and wss://sdp.suki.ai/ws/stream API, and handles common API errors.

Prerequisites

Before you begin, make sure you have:
  • Completed Partner onboarding and received your partner credentials.
  • You have partner_id and partner_token.
  • Optional provider_id or sdp_provider_id if your integration uses Bearer authentication or the Single Auth Token flow.
  • An audio file in LINEAR16 PCM format (16 kHz, mono, 16-bit little-endian). If you’re using a WAV file, remove the WAV header before streaming and send only the raw PCM audio.
Store your partner_token only on your backend. Never expose it in a client-side or public application.

Architecture

Project setup

  1. Create a script or web page in the language used by this tutorial (Python, Go, or TypeScript).
  2. Install the required dependencies:
    • Python: pip install requests websocket-client
    • Go: go get github.com/gorilla/websocket
    • TypeScript (browser): No additional packages are required. The example uses the built-in fetch and WebSocket APIs.
  3. Configure your credentials:
    • Add your partner_id.
    • Store partner_token on your backend only. Never expose it in browser code.
    • Add provider_id or sdp_provider_id only if your integration requires them.
  4. Prepare an audio file in LINEAR16 PCM format or a WAV file. If you use a WAV file, remove the 44-byte WAV header before streaming the PCM audio.

How WebSocket authentication works in this tutorial

Important points to remember:
  • If login fails because the provider is new, Register provider once, then log in again.
  • Send audio at least every 25 seconds, or the server closes the stream. While paused, send KEEP_ALIVE every five seconds.
  • Send raw LINEAR16 PCM. If you start from a WAV file, strip the 44-byte header first. Do not send binary WebSocket frames on this endpoint.
  • Browser protocol order is token, then session ID (SukiAmbientAuth,<sdp_suki_token>,<ambient_session_id>).

Tutorial steps

Work through each step in order. Read the explanation, review the code example, then continue to the next step. The full code example is available in the accordion below.
1

Log In

Call the Login API with your partner credentials to receive a suki_token. Send that token later as sdp_suki_token. If the provider is new, register once, then log in again.
2

Create an Ambient Session

Create a session with the Ambient session API. A successful response returns ambient_session_id (HTTP 201), which you use for context, streaming, end, and retrieve.
3

Add Session Context

Seed provider, patient, and visit context with the Context API before you open the WebSocket so note generation has the encounter details it needs.
4

Open the WebSocket

Connect to wss://sdp.suki.ai/ws/stream. Python and Go send sdp_suki_token and ambient_session_id as HTTP headers. Browser TypeScript uses Sec-WebSocket-Protocol: SukiAmbientAuth,<sdp_suki_token>,<ambient_session_id>.
5

Stream Audio

Send START_TIME, then JSON AUDIO frames with base64 LINEAR16 PCM (~100 ms chunks). End the segment with RU9G. Do not send binary WebSocket frames on this endpoint. Strip a WAV header first if needed.
6

Optional Control Events

While streaming you can send PAUSE, RESUME, or CANCEL as EVENT messages. While paused, send KEEP_ALIVE about every five seconds so idle timeouts do not close the connection. Prefer CANCEL to end the session. ABORT is deprecated and is not handled by the stream handler.
7

End the Session and Retrieve Results

After the WebSocket closes, call End ambient session, poll status until processing finishes, then fetch transcript and content with the retrieve APIs.
8

Handle API Errors

REST failures return JSON with code, message, and details. Map those fields into your client errors and use documented hints for cases such as invalid_sdp_token or provider_not_registered. See API error messages.

Full code example

Python

Troubleshooting

Register the provider once, then log in again.
Send KEEP_ALIVE every five seconds while paused. While streaming, send audio at least every 25 seconds so the server does not close the connection.
Call login again and send the new suki_token as sdp_suki_token, or include it in the browser protocol list. See API errors for related codes.
Confirm the audio is LINEAR16 PCM. If you start from a WAV file, strip the 44-byte header before streaming. Do not send binary WebSocket frames on this endpoint.

Summary

In this tutorial, you:
  • Authenticated with the Suki API.
  • Created an ambient session and seeded the session context.
  • Streamed LINEAR16 PCM audio over a WebSocket connection.
  • Ended the session and retrieved the generated transcript and clinical content.
For production, use the following endpoints:
  • API: https://sdp.suki.ai
  • WebSocket: wss://sdp.suki.ai/ws/stream

Other tutorials

Continue with another end-to-end tutorial.
Ambient

Build a Web SDK Ambient Session

Authenticate, initialize the Web SDK in React, and mount SukiAssistant for an ambient encounter.

15 minIntermediate
APIs

Build a Webhook Notification Receiver

Verify HMAC signatures, parse partner notifications, and handle success and failure events.

10 minBeginner
Last modified on July 24, 2026