-
Notifications
You must be signed in to change notification settings - Fork 120
Description
Summary
Unable to properly pass list of keyterms to connect method in sdk v5.3 for either api version
What happened?
Using deepgram-sdk==5.3.0 for listen endpoints v1 and v2 for both nova-3 and flux-general-en, we are unable to properly send a list of terms to the connect method.
Both client.listen.v1.connect and client.listen.v2.connect expect keyterm to be a str and passing a list won't append to the query_params properly:
As mentioned in this related (v2 only though) issue, this results in the SDK forming a url-encoded list of strings for the keyterm param, instead of properly adding each term separately. As a result, this breaks logic around passing multiple individual keyterms, and also makes it harder to stay within the 100 char limit per term, and the 500 tokens in total.
For v2, this issue was temporarily fixed with the v5.1.0 release but it seems to have regressed in the newer releases.
For v1, this has been broken since the v4 -> v5 change.
Steps to reproduce
- Install
deepgram-sdk==5.3.0 - Try to pass multiple keyterms
keyterm=["term1", ... "termN"]to eitherclient.listen.v1.connectorclient.listen.v2.connect - Observe that they are passed as a url-encoded list of strings instead of individually
&keyterm=term1...&keyterm=termN
Minimal code sample
from deepgram import DeepgramClient
client = DeepgramClient(api_key="key")
terms = ["term1", "term2"]
# can also replace v1 with v2
with client.listen.v1.connect(keyterm=terms) as connection:
# do something with the connectionLogs / traceback
# passing a lot of terms as a url-encoded list will break the length limit faster resulting in the following:
File "/usr/local/lib/python3.11/site-packages/decorator.py", line 235, in fun
return caller(func, *(extras + args), **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/retry/api.py", line 73, in retry_decorator
return __retry_internal(partial(f, *args, **kwargs), exceptions, tries, delay, max_delay, backoff, jitter,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/retry/api.py", line 33, in __retry_internal
return f()
^^^
File "/app/service/plat/speech_to_text/deepgram.py", line 688, in _setup_deepgram_connection
_dg_connection = self._deepgram_connection_exit_stack.enter_context(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/contextlib.py", line 517, in enter_context
result = _enter(cm)
^^^^^^^^^^
File "/usr/local/lib/python3.11/contextlib.py", line 137, in __enter__
return next(self.gen)
^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/deepgram/listen/v1/client.py", line 217, in connect
with websockets_sync_client.connect(ws_url, additional_headers=headers) as protocol:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/websockets/sync/client.py", line 308, in connect
connection.handshake(
File "/usr/local/lib/python3.11/site-packages/websockets/sync/client.py", line 95, in handshake
raise self.protocol.handshake_exc
File "/usr/local/lib/python3.11/site-packages/websockets/client.py", line 340, in parse
self.process_response(response)
File "/usr/local/lib/python3.11/site-packages/websockets/client.py", line 151, in process_response
raise InvalidStatus(response)
websockets.exceptions.InvalidStatus: server rejected WebSocket connection: HTTP 400
Transport
WebSocket
API endpoint / path
/v1/listen and /v2/listen
Model(s) used
nova-3 for v1 and flux-general-en for v2
How often?
Always
Is this a regression?
- Yes, it worked in an earlier version
Last working SDK version (if known)
5.1.0 for v2, 4.8.1 for v1
SDK version
5.3.0
Python version
3.11.14
Install method
uv
OS
Linux (x86_64)
Environment details
Link to minimal repro (optional)
No response
Session ID (optional)
No response
Project ID (optional)
No response
Request ID (optional)
No response
Code of Conduct
- I agree to follow this project’s Code of Conduct