-
Notifications
You must be signed in to change notification settings - Fork 119
fix(websockets): support array parameters in Listen v1 and v2 clients #650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Update WebSocket clients to properly handle parameters that accept both single strings and arrays of strings. Arrays are now correctly expanded into multiple query parameters (e.g., keyterm=term1&keyterm=term2) instead of being URL-encoded as a single stringified array. Fixed parameters in Listen V2: - keyterm: now accepts string | string[] - tag: now accepts string | string[] Fixed parameters in Listen V1: - keyterm: now accepts string | string[] - keywords: now accepts string | string[] - extra: now accepts string | string[] - redact: now accepts string | string[] - replace: now accepts string | string[] - search: now accepts string | string[] - tag: now accepts string | string[] Changes: - Updated client method signatures to accept Union[str, Sequence[str]] - Added runtime type checking to detect and iterate over arrays - Updated type definitions to reflect proper union types - Added documentation for array parameter support This fix ensures consistency with the AsyncAPI/OpenAPI specs and matches the behavior of the REST API clients. Fixes #648 Fixes #629 Related to #616
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a bug in the WebSocket clients (Listen V1 and V2) where array parameters were incorrectly URL-encoded as stringified arrays instead of being expanded into multiple query parameters. The fix ensures arrays are properly handled according to the OpenAPI specification (style: form, explode: true).
Changes:
- Updated type definitions for affected parameters to accept
Union[str, Sequence[str]] - Added runtime type checking to detect arrays and iterate over elements
- Updated method signatures and docstrings to reflect array support
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/deepgram/types/listen_v2tag.py | Updated type definition to support arrays |
| src/deepgram/types/listen_v1tag.py | Updated type definition to support arrays |
| src/deepgram/types/listen_v1search.py | Updated type definition to support arrays |
| src/deepgram/types/listen_v1replace.py | Updated type definition to support arrays |
| src/deepgram/types/listen_v1redact.py | Updated type definition to support arrays while preserving literals |
| src/deepgram/types/listen_v1keywords.py | Updated type definition to support arrays |
| src/deepgram/types/listen_v1keyterm.py | Updated type definition to support arrays |
| src/deepgram/types/listen_v1extra.py | Updated type definition to support arrays |
| src/deepgram/listen/v2/client.py | Added array handling logic and updated signatures for V2Client and AsyncV2Client |
| src/deepgram/listen/v1/client.py | Added array handling logic and updated signatures for V1Client and AsyncV1Client |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ListenV1Redact = typing.Union[ | ||
| typing.Literal["true", "false", "pci", "numbers", "aggressive_numbers", "ssn"], typing.Any | ||
| typing.Literal["true", "false", "pci", "numbers", "aggressive_numbers", "ssn"], | ||
| typing.Sequence[str], | ||
| ] |
Copilot
AI
Jan 29, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type definition should be Optional to maintain consistency with other parameters. The Union should include None, or the entire Union should be wrapped with Optional, as redact is an optional parameter based on the function signature in client.py where it's defined as redact: typing.Optional[typing.Union[str, typing.Sequence[str]]].
|
|
||
| ListenV1Redact = typing.Union[ | ||
| typing.Literal["true", "false", "pci", "numbers", "aggressive_numbers", "ssn"], typing.Any | ||
| typing.Literal["true", "false", "pci", "numbers", "aggressive_numbers", "ssn"], |
Copilot
AI
Jan 29, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type definition should include str as a standalone option in the Union to match the other parameter types and allow any string value (not just the literal values or sequences). The current definition only allows literal strings or sequences, which doesn't align with the Union[str, Sequence[str]] pattern used for other parameters.
| typing.Literal["true", "false", "pci", "numbers", "aggressive_numbers", "ssn"], | |
| typing.Literal["true", "false", "pci", "numbers", "aggressive_numbers", "ssn"], | |
| str, |
- Wrap Union in Optional to match function signature - Add str as standalone option in Union to allow any string value - Maintains Literal types for common values (autocomplete support) Addresses Copilot AI review comments
|
Thanks for the review, Copilot! 🤖 I've addressed both comments regarding Fixed in commit d835960:
New type definition: ListenV1Redact = typing.Optional[
typing.Union[
typing.Literal["true", "false", "pci", "numbers", "aggressive_numbers", "ssn"],
str,
typing.Sequence[str],
]
]This now properly supports:
|
Update test to reflect new type definition: - Changed from Optional[Any] to Optional[Union[str, Sequence[str]]] - Updated test name and docstring for clarity - Usage tests remain unchanged and already cover the correct behavior
✅ All Tests Passing!Fixed the test failures with two additional commits: Commit d835960: Fixed
|
Summary
This PR fixes the WebSocket clients (Listen V1 and V2) to properly handle parameters that accept both single strings and arrays of strings, as defined in the AsyncAPI and OpenAPI specifications.
Problem
When passing arrays to WebSocket connect methods, they were incorrectly URL-encoded as a single stringified array:
This caused the API to reject requests with multiple keyterms, keywords, tags, etc.
Solution
Arrays are now properly expanded into multiple query parameters:
The fix adds runtime type checking to detect arrays and iterates over each element, adding them as separate query parameters. This matches the behavior of the REST API clients and aligns with the OpenAPI spec which defines these parameters with
style: formandexplode: true.Fixed Parameters
Listen V2 (
/v2/listen)keyterm: now acceptsstring | string[]tag: now acceptsstring | string[]Listen V1 (
/v1/listen)keyterm: now acceptsstring | string[]keywords: now acceptsstring | string[]extra: now acceptsstring | string[]redact: now acceptsstring | string[]replace: now acceptsstring | string[]search: now acceptsstring | string[]tag: now acceptsstring | string[]Changes Made
typing.Union[str, typing.Sequence[str]]for affected parametersUsage Examples
Before (Broken)
After (Fixed)
Backward Compatibility
✅ Fully backward compatible: Existing code that passes single strings continues to work exactly as before. This only adds new functionality for arrays.
Testing
Tested with:
The generated query strings now match the expected format:
Modified Files
src/deepgram/listen/v1/client.py- UpdatedV1Client.connect()andAsyncV1Client.connect()src/deepgram/listen/v2/client.py- UpdatedV2Client.connect()andAsyncV2Client.connect()src/deepgram/types/listen_v1keyterm.py- Type definitionsrc/deepgram/types/listen_v1keywords.py- Type definitionsrc/deepgram/types/listen_v1extra.py- Type definitionsrc/deepgram/types/listen_v1redact.py- Type definitionsrc/deepgram/types/listen_v1replace.py- Type definitionsrc/deepgram/types/listen_v1search.py- Type definitionsrc/deepgram/types/listen_v1tag.py- Type definitionsrc/deepgram/types/listen_v2tag.py- Type definitionCloses
Fixes #648
Fixes #629
Related to #616