STT Troubleshooting WebSocket, NET, and DATA Errors

Learn how to debug common real-time, live streaming transcription errors.

When working with Deepgram’s Speech To Text Streaming API, you may encounter WebSocket errors. This troubleshooting guide helps you quickly identify and resolve the most common issues.

WebSocket Basics

  • WebSocket enables two-way, real-time communication between client and server.
  • The connection is established via an HTTP handshake and upgraded to WebSocket.
  • If the handshake fails, you’ll get an HTTP 4xx or 5xx error.
  • The connection stays open until closed by either side.

Establishing a WebSocket Connection

  • The client initiates a WebSocket connection with an HTTP handshake, optionally including query parameters or headers (for authentication, etc.).
  • Most libraries handle the handshake automatically (e.g., websockets.connect).
  • If successful, the server responds with HTTP 101 and upgrades the connection.
  • If unsuccessful, you’ll receive an HTTP 4xx or 5xx error and the connection won’t be established.

Closing the WebSocket Connection

  • A successfully opened WebSocket connection will stay alive until it is eventually closed by either the client or the server. When this occurs, a WebSocket Close Frame will be returned.
  • The body of the Close frame will indicate the reason for closing with a pre-defined status code followed by a UTF-8-encoded payload that represents the reason for the error.
  • To close the WebSocket connection from your client, send a Close Stream message. The server will then finish processing any remaining data, send a final response and summary metadata, and terminate the connection.
  • After sending a Close message, the endpoint considers the WebSocket connection closed and will close the underlying TCP connection.

Sending an empty byte (e.g., b'') will cause unexpected closures. Avoid sending an empty byte accidentally by adding a conditional to check if the length of your audio packet is 0 before sending.

Using KeepAlive Messages to Prevent Timeouts

  • Send a KeepAlive message periodically to keep the connection open.
  • Doing this can prevent timeouts and NET-0001 errors (no audio received for 10 seconds).

Common WebSocket Errors

Failure to Connect

If a failure to connect occurs, Deepgram returns custom HTTP headers for debugging:

  • dg-request-id: Always present, contains the request ID.
  • dg-error: Present on failed upgrades, contains the error message.

Access to these headers will depend on the WebSocket library you are using. For example, browser-based WebSocket libraries like the JavaScript WebSocket library only allow access to HTTP header information for successful WebSocket connections.

Debugging Connection Failures

If you’re unable to connect the Deepgram API provides custom HTTP headers that contain debugging information:

  • Regardless of the success or failure of the WebSocket upgrade, all requests include the dg-request-id HTTP header, which contains the request ID.
  • Requests that do not successfully upgrade to a WebSocket connection also include the dg-error HTTP header, which contains a detailed error message concerning why the connection could not be upgraded. This error message is also sent back in the body of the HTTP response.

Code Samples

These code samples demonstrate how to connect to Deepgram’s API using WebSockets, authenticate with your API key, and handle both successful and failed connection attempts by printing relevant request IDs and error messages for troubleshooting.

Replace YOUR_DEEPGRAM_API_KEY with your Deepgram API Key.

1import websockets
2import json
3import asyncio
4
5async def main():
6 try:
7 async with websockets.connect('wss://api.deepgram.com/v1/listen',
8 # Remember to replace the YOUR_DEEPGRAM_API_KEY placeholder with your Deepgram API Key
9 extra_headers = { 'Authorization': f'token YOUR_DEEPGRAM_API_KEY' }) as ws:
10 # If the request is successful, print the request ID from the HTTP header
11 print('🟢 Successfully opened connection')
12 print(f'Request ID: {ws.response_headers["dg-request-id"]}')
13 await ws.send(json.dumps({
14 'type': 'CloseStream'
15 }))
16 except websockets.exceptions.InvalidStatusCode as e:
17 # If the request fails, print both the error message and the request ID from the HTTP headers
18 print(f'🔴 ERROR: Could not connect to Deepgram! {e.headers.get("dg-error")}')
19 print(f'🔴 Please contact Deepgram Support with request ID {e.headers.get("dg-request-id")}')
20
21asyncio.run(main())

Abrupt WebSocket Closures

If Deepgram encounters an error during real-time streaming, the Deepgram API returns a WebSocket Close frame. The body of the Close frame will indicate the reason for closing with a pre-defined status code followed by a UTF-8-encoded payload that represents the reason for the error.

Below are the most common WebSocket Close frame status codes and their descriptions.

CodePayloadDescription
1008DATA-0000The payload cannot be decoded as audio. The payload either is not audio data or is a codec unsupported by Deepgram.
1011NET-0000The service has not transmitted a Text frame to the client within the timeout window. This may indicate an internal issue with Deepgram’s systems, or Deepgram may have not received enough audio data to transcribe a frame.
1011NET-0001The service has not received a Binary or Text frame from the client within the timeout window. This may indicate an internal issue with Deepgram’s systems, the client’s systems, or the network connecting them.

Troubleshooting 1008 - DATA-0000

  • Check the data being sent is valid audio.
  • Check the audio data is not empty.
  • If the audio data is valid, check whether the audio being sent is raw or containerized.
  • Write the audio data to a file to make sure it contains the expected audio and can be played back.
  • Ensure Encoding and Sample Rate parameters are set correctly.
  • See Audio Format For Live Streaming for more information.

Troubleshooting 1011 - NET-0000

  • This indicates an internal server error.
  • Retry your request.
  • Check Deepgram status to see if there are any ongoing issues.
  • If Deepgram is operational, contact Support for assistance.

Troubleshooting 1011 - NET-0001

  • Ensure audio is sent within 10 seconds of opening the connection.
  • You can send silent audio to keep the connection alive.
  • Using KeepAlive messages alone will not prevent closure; you must send at least one audio message.
  • Be sure to send a Close Stream message when done.
  • Test your network with cURL and Deepgram-hosted audio. See Generating Transcripts from the Terminal for more information.
  • Use a tool like Wireshark to confirm audio is leaving your network.