Hi i have faced this issue on prodcution. ```aioh...
# ask-ai
b
Hi i have faced this issue on prodcution.
Copy code
aiohttp.client_exceptions.WSServerHandshakeError: 408, message='Invalid response status', 
url="<wss://api.deepgram.com/v1/listen?model=nova-3&punctuate=true&smart_format=false&no_delay=true&interim_results=true&encoding=linear16&vad_events=true&sample_rate=8000&channels=1&endpointing=1200&filler_words=true&profanity_filter=false&numerals=false&mip_opt_out=false&keyterm=>..."
Whts this issue tho
t
Thanks for reaching out, Sathwik. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm sorry to hear you're encountering the error
aiohttp.client_exceptions.WSServerHandshakeError: 408
. This means the WebSocket Server Handshake timed out, which happens when the server doesn't complete the handshake within the expected time. I understand how frustrating that can be! Here are some common reasons this might happen: • Network latency or packet loss between your device and the server • Server processing delays or too much load on the server • Firewalls, proxies, or NAT settings that might be blocking or slowing down the connection • Incorrect or unreachable WebSocket URLs • Timeout settings on the client or server side that might be too strict To help you troubleshoot, you might want to try these steps: 1. Test your WebSocket connection using tools like the Connection Test utility to see if it’s working properly. 2. Check if any firewalls, proxies, or VPNs could be interfering with the WebSocket traffic. 3. Take a look at your timeout settings in the code and consider adjusting them if they seem too tight. 4. Double-check that the WebSocket URL you’re using is correct and accessible. Please feel free to reach out if you'd like me to walk you through any of these steps or if you have more questions. I'm here to help! Sources: SIP troubleshooting guide | LiveKit Docs | livekit-plugins/livekit-plugins-assemblyai/livekit/plugins/assemblyai/stt.p... | Diagnosing Connection Errors with Connection Test Utility | lib/src/exceptions.dart
b
Its not firewall def, and its happening with few calls. but i need a solid solution or clear note its an issue from Livekit or deepgram wht ever u think Just need some clarity on this
t
To help you figure out whether the WebSocket handshake timeout (408) is coming from LiveKit or Deepgram, here’s a simple way to approach it: 1. Take a look at the error logs: If you see messages like "failed to connect to deepgram" or an
APIConnectionError
, it’s likely something with Deepgram’s API connection. On the other hand, if the error is from LiveKit SDKs mentioning
ServerUnreachable
, it usually means there’s a LiveKit signaling issue. 2. Try the LiveKit Connection Tests: You can use the LiveKit Connection Test tool to check WebSocket, WebRTC, and TURN connectivity. If those tests pass but Deepgram connections still fail, then the problem is probably with Deepgram. 3. Double-check your network and credentials: Make sure the WebSocket URL, network settings, and API credentials for Deepgram are all correct and working properly. If you’d like, I’m here to help you run these tests or go over the results together. Just let me know! Sources: livekit-plugins/livekit-plugins-soniox/livekit/plugins/soniox/stt.py | src/room/participant/LocalParticipant.ts | Diagnosing Connection Errors with Connection Test Utility
b
Copy code
{"message": "Error in _stt_task\nTraceback (most recent call last):\n  File \"/home/azureuser/QuantumLoop/EmmaLiveKit/.venv/lib/python3.12/site-packages/livekit/agents/stt/stt.py\", line 367, in _anext_\n    val = aw
ait self._event_aiter._anext_()\n          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nStopAsyncIteration\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File
\"/home/azureuser/QuantumLoop/EmmaLiveKit/.venv/lib/python3.12/site-packages/livekit/agents/utils/log.py\", line 16, in async_fn_logs\n    return await fn(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^\n  File
\"/home/azureuser/QuantumLoop/EmmaLiveKit/.venv/lib/python3.12/site-packages/livekit/agents/voice/audio_recognition.py\", line 452, in _stt_task\n    async for ev in node:\n  File \"/home/azureuser/QuantumLoop/EmmaLive
Kit/.venv/lib/python3.12/site-packages/livekit/agents/voice/agent.py\", line 352, in stt_node\n    async for event in stream:\n  File \"/home/azureuser/QuantumLoop/EmmaLiveKit/.venv/lib/python3.12/site-packages/livekit
/agents/stt/stt.py\", line 370, in _anext_\n    raise exc  # noqa: B904\n    ^^^^^^^^^\n  File \"/home/azureuser/QuantumLoop/EmmaLiveKit/.venv/lib/python3.12/site-packages/livekit/agents/stt/stt.py\", line 251, in _m
ain_task\n    return await self._run()\n           ^^^^^^^^^^^^^^^^^\n  File \"/home/azureuser/QuantumLoop/EmmaLiveKit/.venv/lib/python3.12/site-packages/livekit/plugins/deepgram/stt.py\", line 488, in _run\n    ws = a
wait self._connect_ws()\n         ^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/home/azureuser/QuantumLoop/EmmaLiveKit/.venv/lib/python3.12/site-packages/livekit/plugins/deepgram/stt.py\", line 550, in _connect_ws\n    ws = awai
t asyncio.wait_for(\n         ^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/lib/python3.12/asyncio/tasks.py\", line 520, in wait_for\n    return await fut\n           ^^^^^^^^^\n  File \"/home/azureuser/QuantumLoop/EmmaLiveKi
t/.venv/lib/python3.12/site-packages/aiohttp/client.py\", line 1084, in _ws_connect\n    raise WSServerHandshakeError(\naiohttp.client_exceptions.WSServerHandshakeError: 408, message='Invalid response status', url=\"ws
<s://api.deepgram.com/v1/listen?model=nova-3&punctuate=true&smart_format=false&no_delay=true&interim_results=true&encoding=linear16&vad_events=true&sample_rate=8000&channels=1&endpointing=1200&filler_words=true&profanit>
y_filter=false&numerals=false&mip_opt_out=false&keyterm=sick+note&keyterm=fit+note&keyterm=doctor's+note&keyterm=myself&keyterm=doctor's+letter&keyterm=repeat+prescription&keyterm=medication&keyterm=prescription&keyter
m=Check+up&keyterm=Pill+review&keyterm=review&keyterm=Medical&keyterm=worse&keyterm=telephone+appointment&keyterm=referral&keyterm=Oral+thrush&keyterm=blood+test&keyterm=urine+test&keyterm=scan&keyterm=ultrasound&keyte
rm=test&keyterm=chest+pain&keyterm=breath&keyterm=asthma&keyterm=diabetes&keyterm=blood+pressure&keyterm=pregnancy&keyterm=contraception&keyterm=smear+test&keyterm=vaccination&keyterm=hospital+letter&keyterm=pharmacy&k
eyterm=district+nurse&keyterm=midwife&keyterm=flu&keyterm=jab&keyterm=vaccine&keyterm=repeat&keyterm=pain&keyterm=covid&keyterm=ibuprofen&keyterm=paracetamol&keyterm=sharp&keyterm=cough&language=en\"", "level": "ERROR"
, "name": "livekit.agents", "pid": 761732, "job_id": "AJ_5o8UJyN8RN2g", "timestamp": "2025-09-24T09:50:22.972040+00:00"}
This is the error
t
Thanks for sharing the error trace! It looks like the WebSocket handshake timeout (408) is happening while connecting to Deepgram's API. This usually points to something with the Deepgram plugin or its setup rather than LiveKit itself. Let’s try these steps to get things working smoothly: 1. Increase the connection timeout: Try adjusting the
conn_options.timeout
value in the Deepgram plugin to give the handshake a bit more time—around 10–15 seconds often helps. 2. Send audio data promptly: Make sure audio frames start flowing right after the WebSocket connection opens to prevent any server-side timeouts. 3. Send keep-alive messages: Check that keep-alive messages are being sent during any idle moments to keep the connection healthy. 4. Check API key and network reachability: Double-check that your Deepgram API key is valid and that the WebSocket URL is accessible without any network blocks. 5. Enable retries: Adding retry logic for the WebSocket connection can help handle any temporary hiccups. Could you share what your current timeout settings are and if the audio is being sent immediately after connecting? That info will really help me guide you better. Sources: SIP troubleshooting guide | LiveKit Docs | livekit-plugins/livekit-plugins-soniox/livekit/plugins/soniox/stt.py
b
The current timeout - 30seconds Yes the audio is being sent immediately
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!