We're excited to announce an update to our streaming API for enhanced usability.
Working with websockets to send audio in real-time can be tricky. Today, we're releasing the first step in our plan to make our streaming API easier to use.
Streaming connections should now be closed by sending the JSON message { "type": "CloseStream" }. This tells Deepgram that no more audio will be sent. Deepgram will then finish processing existing audio, and close the connection once all transcripts are returned.
Gracefully closing your stream is the best way to ensure you get all your transcripts, and aren't charged for audio you don't want transcribed.
Here's an example of sending a CloseStream message in Javascript:
And an example in Python:
Previously, streaming connections were closed by sending an empty byte—for example, sending Uint8Array(0) in Javascript, or b'' in Python. This method of closing connections is now deprecated, and we will remove it in a future release. An empty byte doesn't inherently translate to closing a connection and some websocket libraries don't support sending it. Sending a CloseStream message is a clearer and more universal method to accomplish this.
We recommend customers using our API move to using the CloseStream method to avoid potential disruptions. Any customers using our SDK will not need to make changes.
This message is the first of many. We'll be releasing additional JSON messages in the coming months that will unlock powerful new features in our real-time API. Stay tuned!
To learn more about Streaming, please refer to our Streaming Documentation. We welcome your feedback, please share it with us here.
If you have any feedback about this post, or anything else around Deepgram, we'd love to hear from you. Please let us know in our GitHub discussions .
Unlock language AI at scale with an API call.
Get conversational intelligence with transcription and understanding on the world's best speech AI platform.