Skip to content

Conversation

@lukeocodes
Copy link
Contributor

Summary

Fixes #617

Changed SpeakV1WarningEvent field names from code/description to warn_code/warn_msg to match the actual field names returned by the Deepgram API.

Issue

When the Deepgram API returns a 429 rate limit warning, the response contains:

{
  "type": "Warning",
  "warn_code": "EXCESSIVE_FLUSH",
  "warn_msg": "Rate limit exceeded for flushes. Please try again later."
}

However, the SDK's SpeakV1WarningEvent model was expecting code and description fields instead, causing a Pydantic validation error that crashed the TTS WebSocket connection instead of calling the on_warning callback.

Changes

  1. Updated SpeakV1WarningEvent model:

    • Changed code: strwarn_code: str
    • Changed description: strwarn_msg: str
  2. Updated all related tests to use the correct field names

Impact

  • ✅ TTS WebSocket connections will now handle warning messages gracefully instead of crashing
  • ✅ The on_warning callback will be properly invoked for 429 rate limit warnings
  • ✅ Matches the SDK v4.8 behavior where warnings were handled correctly
  • ✅ All existing tests updated and passing

Test plan

  • Updated all unit tests in test_speak_v1_models.py to use new field names
  • Tests verify:
    • Valid warning event creation
    • Serialization/deserialization
    • Missing required fields validation
    • Wrong type validation
    • Multiple warning scenarios

Changed SpeakV1WarningEvent field names from `code`/`description` to
`warn_code`/`warn_msg` to match the actual field names returned by the
Deepgram API. This fixes Pydantic validation errors that were causing
TTS WebSocket connections to crash instead of calling the on_warning
callback when receiving 429 rate limit warnings.

Updated all related tests to use the correct field names.

Fixes #617
Copilot AI review requested due to automatic review settings January 29, 2026 22:12
Copy link
Contributor

Copilot AI left a 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 TTS WebSocket warning event handling by updating the SpeakV1WarningEvent model field names to match the actual Deepgram API response format, preventing validation errors that previously caused crashes.

Changes:

  • Updated SpeakV1WarningEvent model fields from code/description to warn_code/warn_msg
  • Updated all related unit tests to use the corrected field names

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/deepgram/extensions/types/sockets/speak_v1_warning_event.py Updated field names in the warning event model to match API response
tests/unit/test_speak_v1_models.py Updated all test cases to use the corrected field names

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

naomi-deepgram
naomi-deepgram previously approved these changes Jan 29, 2026
- Change docstring from 'Error code' to 'Warning code' to accurately reflect warning events
- Fix test scenarios to consistently use warn_msg/warn_code field names
@lukeocodes lukeocodes merged commit f7ab1da into main Jan 29, 2026
13 checks passed
@lukeocodes lukeocodes deleted the fix/tts-warning-field-names branch January 29, 2026 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: TTS fails to parse 429 warning message

3 participants