Skip to content

Fix ElevenLabs websocket context id handling#5813

Open
flynn-hamming wants to merge 1 commit into
livekit:mainfrom
flynn-hamming:flynnlachendro/eng-18298-fix-elevenlabs-context-id
Open

Fix ElevenLabs websocket context id handling#5813
flynn-hamming wants to merge 1 commit into
livekit:mainfrom
flynn-hamming:flynnlachendro/eng-18298-fix-elevenlabs-context-id

Conversation

@flynn-hamming
Copy link
Copy Markdown

Summary

Fix ElevenLabs multi-context websocket handling so the TTS plugin accepts both contextId and context_id response fields.

ElevenLabs' multi-context websocket API uses snake_case context_id in client messages, and current websocket responses can also include context_id. The plugin only reads camelCase contextId, so valid audio/final messages can be treated as unexpected messages when the response uses snake_case. In LiveKit fallback setups, this can cause ElevenLabs audio to be skipped and a fallback TTS provider to be used instead.

This change keeps existing contextId handling, adds context_id compatibility, and treats flush_done messages for inactive contexts as harmless lifecycle messages.

Tests

uv run ruff format livekit-plugins/livekit-plugins-elevenlabs/livekit/plugins/elevenlabs/tts.py tests/test_plugin_elevenlabs_tts.py
uv run ruff check livekit-plugins/livekit-plugins-elevenlabs/livekit/plugins/elevenlabs/tts.py tests/test_plugin_elevenlabs_tts.py
uv run pytest tests/test_plugin_elevenlabs_tts.py

Result:

10 passed

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 22, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

@flynn-hamming
Copy link
Copy Markdown
Author

Hey folks, quick bit of context on why I opened this.

We hit this while testing ElevenLabs streaming voices in a production-ish voice-agent flow. ElevenLabs was sending websocket messages with context_id, but the plugin only looked for contextId, so valid audio messages were getting treated as unexpected and our app fell back to the next TTS provider.

The change is intentionally tiny: keep supporting contextId, also accept context_id, and ignore harmless flush_done lifecycle messages for contexts that are already closed.

Happy to tweak the shape/tests if there is a preferred LiveKit style here. Thanks!

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.

2 participants