strong-air-82340
02/18/2026, 10:35 AM\nTraceback (most recent call last):\n File \"/code/.venv/lib/python3.12/site-packages/livekit/plugins/sarvam/tts.py\", line 557, in send_task\n await ws.send_str(json.dumps(config_msg))\n File \"/code/.venv/lib/python3.12/site-packages/aiohttp/client_ws.py\", line 245, in send_str\n await self._writer.send_frame(\n File \"/code/.venv/lib/python3.12/site-packages/aiohttp/_websocket/writer.py\", line 83, in send_frame\n self._write_websocket_frame(message, opcode, 0)\n File \"/code/.venv/lib/python3.12/site-packages/aiohttp/_websocket/writer.py\", line 151, in _write_websocket_frame\n raise ClientConnectionResetError(\"Cannot write to closing transport\")\naiohttp.client_exceptions.ClientConnectionResetError: Cannot write to closing transport\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"/code/.venv/lib/python3.12/site-packages/livekit/plugins/sarvam/tts.py\", line 629, in _run_ws\n await asyncio.gather(*tasks)\n File \"/code/.venv/lib/python3.12/site-packages/livekit/plugins/sarvam/tts.py\", line 579, in send_task\n raise APIConnectionError(f\"Send task failed: {e}\") from e\nlivekit.agents._exceptions.APIConnectionError: Send task failed: Cannot write to closing transport (body=None, retryable=True)\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"/code/.venv/lib/python3.12/site-packages/livekit/plugins/sarvam/tts.py\", line 518, in _run\n await asyncio.gather(*tasks)\n File \"/code/.venv/lib/python3.12/site-packages/livekit/plugins/sarvam/tts.py\", line 511, in _process_segments\n await self._run_ws(word_stream, output_emitter)\n File \"/code/.venv/lib/python3.12/site-packages/livekit/plugins/sarvam/tts.py\", line 657, in _run_ws\n raise APIStatusError(f\"TTS WebSocket session failed: {e}\") from e\nlivekit.agents._exceptions.APIStatusError: TTS WebSocket session failed: Send task failed: Cannot write to closing transport (body=None, retryable=True) (status_code=-1, request_id=None, body=None, retryable=True)\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"/code/.venv/lib/python3.12/site-packages/livekit/agents/tts/tts.py\", line 452, in _main_task\n await self._run(output_emitter)\n File \"/code/.venv/lib/python3.12/site-packages/livekit/plugins/sarvam/tts.py\", line 526, in _run\n raise APIConnectionError() from e\nlivekit.agents._exceptions.APIConnectionError: Connection error. (body=None, retryable=True)", "level": "WARNING", "name": "livekit.agents", "exc_info": "Traceback (most recent call last):\n File \"/code/.venv/lib/python3.12/site-packages/livekit/plugins/sarvam/tts.py\", line 557, in send_task\n await ws.send_str(json.dumps(config_msg))\n File \"/code/.venv/lib/python3.12/site-packages/aiohttp/client_ws.py\", line 245, in send_str\n await self._writer.send_frame(\n File \"/code/.venv/lib/python3.12/site-packages/aiohttp/_websocket/writer.py\", line 83, in send_frame\n self._write_websocket_frame(message, opcode, 0)\n File \"/code/.venv/lib/python3.12/site-packages/aiohttp/_websocket/writer.py\", line 151, in _write_websocket_frame\n raise ClientConnectionResetError(\"Cannot write to closing transport\")\naiohttp.client_exceptions.ClientConnectionResetError: Cannot write to closing transport\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"/code/.venv/lib/python3.12/site-packages/livekit/plugins/sarvam/tts.py\", line 629, in _run_ws\n await asyncio.gather(*tasks)\n File \"/code/.venv/lib/python3.12/site-packages/livekit/plugins/sarvam/tts.py\", line 579, in send_task\n raise APIConnectionError(f\"Send task failed: {e}\") from e\nlivekit.agents._exceptions.APIConnectionError: Send task failed: Cannot write to closing transport (body=None, retryable=True)\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"/code/.venv/lib/python3.12/site-packages/livekit/plugins/sarvam/tts.py\", line 518, in _run\n await asyncio.gather(*tasks)\n File \"/code/.venv/lib/python3.12/site-packages/livekit/plugins/sarvam/tts.py\", line 511, in _process_segments\n await self._run_ws(word_stream, output_emitter)\n File \"/code/.venv/lib/python3.12/site-packages/livekit/plugins/sarvam/tts.py\", line 657, in _run_ws\n raise APIStatusError(f\"TTS WebSocket session failed: {e}\") from e\nlivekit.agents._exceptions.APIStatusError: TTS WebSocket session failed: Send task failed: Cannot write to closing transport (body=None, retryable=True) (status_code=-1, request_id=None, body=None, retryable=True)\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"/code/.venv/lib/python3.12/site-packages/livekit/agents/tts/tts.py\", line 452, in _main_task\n await self._run(output_emitter)\n File \"/code/.venv/lib/python3.12/site-packages/livekit/plugins/sarvam/tts.py\", line 526, in _run\n raise APIConnectionError() from e\nlivekit.agents._exceptions.APIConnectionError: Connection error. (body=None, retryable=True)", "tts": "livekit.plugins.sarvam.tts.TTS", "attempt": 1, "streamed": true, "pid": 94, "job_id": "AJ_mAZzaYaK8DsZ", "room_id": "RM_7dkC93y4WRFu", "timestamp": "2026-02-18T10:26:27.954996+00:00"}tall-airline-16756
02/18/2026, 10:35 AMtall-airline-16756
02/18/2026, 10:36 AMCannot write to closing transport). I’ll walk you through targeted checks and actions to isolate and resolve this.
What this means
• The Sarvam WebSocket session is being closed unexpectedly while the plugin is trying to send the config message for synthesis.
• The plugin surfaces this as retryable connection errors, but frequent occurrences indicate an underlying connectivity, credentials, or service-side issue.
Please try these steps in order
1) Confirm Sarvam credentials
• Verify SARVAM_API_KEY is set correctly in your environment (.env) and hasn’t expired or been rotated.
• If there’s any doubt, regenerate the key in the Sarvam dashboard and update your server.
2) Verify network connectivity to Sarvam
• Ensure your server can open and maintain WebSocket connections to Sarvam’s endpoint (e.g., <wss://api.sarvam.ai> or the endpoint you configured).
• From the host running the agent, run a simple WebSocket/connectivity test or a curl/telnet check to the endpoint and observe dropouts.
• If you’re behind a firewall, proxy, or cloud security group, make sure WebSocket (wss://) traffic is allowed and persistent connections are not terminated prematurely.
3) Check Sarvam service status and rate limits
• Confirm Sarvam’s API is operational (any scheduled downtime, throttling, or rate limits could close connections).
• If you suspect rate limiting, reduce request frequency or add exponential backoff.
4) Increase logging to capture lifecycle details
• Add logs around the WebSocket open/close events in the Sarvam plugin to record:
◦ When the socket opens
◦ Any close codes or reasons returned
◦ Timing between open and send attempts
• This will show whether the socket closes immediately, after an auth handshake, or mid-send.
5) Ensure retries/backoff are configured
• The plugin treats this as retryable. Confirm your agent’s retry policy/backoff is reasonable (slower backoff and more attempts can help when transient network blips occur).
6) Keep plugin and deps up to date
• Update the Sarvam plugin and aiohttp (the WebSocket client library) to the latest stable versions—connection handling fixes are commonly released.
• After updating, re-run and compare logs.
7) Temporary fallback to isolate the issue
• Try switching to another TTS provider (for example, ElevenLabs or Cartesia) for a short test. If the other provider works reliably, the problem is likely specific to Sarvam connectivity or their service.
• If all TTS providers fail similarly, the issue is likely on your network or runtime environment.
If you can, please share (if safe to share)
• Whether the host is behind a corporate firewall/proxy or runs in a managed cloud environment.
• Whether the errors happen immediately or after some successful syntheses (constant vs intermittent).
• Any socket close codes or additional log lines around the moment the WebSocket closes (if you add logging as suggested).
Next steps I can help with
• Walk you through a small WebSocket connectivity test command you can run from your host.
• Show exactly where to add lifecycle logging in livekit/plugins/sarvam/tts.py to capture the close reason.
• Suggest retry/backoff settings to use while you investigate.
If you share the additional details above (network environment, whether errors are intermittent or immediate, and any socket close codes you capture), I’ll give the next precise troubleshooting commands and code snippets.
Sources: Sarvam TTS plugin guide | LiveKit Documentation | Firewall Tips for LiveKit Connectivity | LiveKit | Text-to-speech (TTS) models overview | LiveKit Documentationstrong-air-82340
02/18/2026, 10:42 AMtall-airline-16756
02/18/2026, 10:42 AMCannot write to closing transport and the full traceback (you already have it).
◦ Whether failures are immediate or occur after some successful syntheses.
◦ Frequency and timing pattern (every request, intermittent, after X seconds).
◦ Your environment (self-hosted VM, Kubernetes, behind proxy/load-balancer, or corporate firewall).
◦ The endpoint you’re connecting to (e.g., <wss://api.sarvam.ai>) and which SDK/version you’re using (plugin and aiohttp versions).
◦ Any network intermediaries (reverse proxy, TLS terminator, or WAF) and whether they have idle timeouts.
◦ Your current retry/backoff behavior (how many retries, backoff intervals).
Why these details help
• The traceback shows the socket is closing during send, but Sarvam will need timing, environment, and SDK versions to determine if it’s a service-side timeout, rate-limiting, client behavior, or network intermediary closing the connection.
Alternate ask if you want Sarvam to act
• “Can you check your WebSocket close logs for our account/requests around timestamp X (include a sample timestamp from your logs) and let us know the close code/reason?”
If you’d like, I can:
• Draft a ready-to-send message including the exact traceback and timestamps.
• Produce a concise summary of the environment and steps to reproduce that you can paste into Sarvam’s support form or email.