Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/deepgram/listen/v1/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def connect(
endpointing: typing.Optional[str] = None,
extra: typing.Optional[str] = None,
interim_results: typing.Optional[str] = None,
keyterm: typing.Optional[str] = None,
keywords: typing.Optional[str] = None,
keyterm: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
keywords: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
language: typing.Optional[str] = None,
mip_opt_out: typing.Optional[str] = None,
model: str,
Expand Down
2 changes: 1 addition & 1 deletion src/deepgram/listen/v2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def connect(
eager_eot_threshold: typing.Optional[str] = None,
eot_threshold: typing.Optional[str] = None,
eot_timeout_ms: typing.Optional[str] = None,
keyterm: typing.Optional[str] = None,
keyterm: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
Copy link
Contributor

@coderabbitai coderabbitai bot Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify httpx.QueryParams.add() handles sequences correctly.

The type signature update looks good and enables multi-value support. However, ensure that httpx.QueryParams.add() at lines 102-103 correctly serializes a sequence into multiple query parameters with the same key (e.g., ?keyterm=val1&keyterm=val2).

Run the following script to verify httpx behavior:


🏁 Script executed:

#!/bin/bash
# Description: Test httpx.QueryParams.add() behavior with sequences

python << 'EOF'
import httpx

# Test with string
qp = httpx.QueryParams()
qp = qp.add("keyterm", "single")
print("Single string:", str(qp))

# Test with list
qp2 = httpx.QueryParams()
qp2 = qp2.add("keyterm", ["val1", "val2"])
print("List of strings:", str(qp2))

# Test with tuple
qp3 = httpx.QueryParams()
qp3 = qp3.add("keyterm", ("val1", "val2"))
print("Tuple of strings:", str(qp3))
EOF

Length of output: 142


🏁 Script executed:

#!/bin/bash
# Check the actual implementation at lines 102-103 and surrounding context
sed -n '95,110p' src/deepgram/listen/v2/client.py

Length of output: 870


🏁 Script executed:

#!/bin/bash
# Check if other parameters use sequences and how they're handled
rg -n "typing.Sequence" src/deepgram/listen/v2/client.py | head -20

Length of output: 84



---

🌐 Web query:

```web
httpx QueryParams add multiple values same key

💡 Result:

Use a dict whose value is a list (httpx does not accept a list-of-tuples for params). Example:

If you need advanced merging/serialization (custom list formats, preserving order, etc.) consider httpx-qs. [1][2]

Sources:
[1] HTTPX compatibility / Query Parameters (requests -> httpx differences). [3search2]
[2] httpx-qs (extra query-string control). [0search6]


Fix httpx.QueryParams.add() to properly handle keyterm sequences.

The type signature at line 46 allows Union[str, Sequence[str]], but the implementation at line 102 uses .add("keyterm", keyterm) which incorrectly stringifies sequences instead of expanding them into multiple query parameters.

When keyterm=["val1", "val2"] is passed, httpx produces keyterm=%5B%27val1%27%2C+%27val2%27%5D instead of the correct keyterm=val1&keyterm=val2.

Solution: Check if keyterm is a sequence and add multiple parameters, or iterate through the sequence:

if keyterm is not None:
    if isinstance(keyterm, str):
        query_params = query_params.add("keyterm", keyterm)
    else:
        for term in keyterm:
            query_params = query_params.add("keyterm", term)
🤖 Prompt for AI Agents
In src/deepgram/listen/v2/client.py around line 46 and the query-building at
~line 102, the code currently does query_params = query_params.add("keyterm",
keyterm) which stringifies sequences; change it to detect if keyterm is None, a
str, or a sequence (e.g., isinstance(keyterm, str) to treat strings as scalar,
otherwise iterate the sequence) and call query_params.add("keyterm", term) for
each element so multiple keyterm entries are added (keyterm=val1&keyterm=val2)
instead of encoding the whole list.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lukeocodes might be worth looking at.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not only is it right, this file should have been updated by Fern.

Shit, i'll need to look into this

mip_opt_out: typing.Optional[str] = None,
tag: typing.Optional[str] = None,
authorization: typing.Optional[str] = None,
Expand Down