miniature-egg-88949
12/12/2025, 5:03 AM{
"level": 50,
"time": 1765515482624,
"pid": 347,
"hostname": "ip-10-0-6-33.ap-south-1.compute.internal",
"jobID": "AJ_cZxwNkUDfC5Q",
"err": {
"type": "APIConnectionError",
"message": "failed to generate TTS completion after 4 attempts",
"stack": "APIConnectionError: failed to generate TTS completion after 4 attempts\n at SynthesizeStream.mainTask (file:///app/node_modules/@livekit/agents/dist/tts/tts.js:73:19)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)",
"body": null,
"retryable": false,
"name": "APIConnectionError"
},
"msg": "failed to generate TTS completion after 4 attempts"
}tall-airline-16756
12/12/2025, 5:03 AMtall-airline-16756
12/12/2025, 5:03 AM@livekit/agents-plugin-cartesia)?
1. If using the Cartesia plugin:
◦ Confirm CARTESIA_API_KEY is set on the host where the agent runs.
1. Network & connectivity
◦ From the agent host, can you reach Cartesia API (e.g., resolve/connect to api.cartesia.ai)? Any firewalls/egress rules or proxies in front of the agent?
1. Voice / descriptor validity
◦ Are you using a built-in Cartesia voice ID? If using the Inference descriptor, is it formatted like cartesia/sonic-3:voice_id?
1. Agent resource/host health
◦ Any CPU/memory spikes or OOMs around the timestamps of the error? Provide short logs (30–60s) before and after one error occurrence if possible.
1. Frequency & pattern
◦ Does the error happen for all TTS requests or intermittently for specific prompts/voices/rooms?
If you’d like, share:
• The exact TTS config snippet you use (mask any secrets).
• A small log excerpt (timestamps + a few lines before/after the error).
What I can do next once you reply:
• If it’s an auth issue, I’ll list exact env vars/locations to check.
• If it’s networking, I’ll suggest concrete tests you can run from the host and what to look for.
• If retries/fallbacks are needed, I can show how to add a FallbackAdapter or alternative TTS flow.
Which integration are you using (Inference or plugin), and can you paste the TTS config (with secrets removed)?
Sources: How to detect when an agent has finished speaking | Cartesia TTS | LiveKit docs | Cartesia TTS plugin guide | LiveKit docs | Models | LiveKit Docs | Events and error handling | LiveKit docsminiature-egg-88949
12/12/2025, 5:12 AMtall-airline-16756
12/12/2025, 5:12 AMGET / if available
2) Network connectivity under load
• While you trigger the LLM tool (reproduce the failure), run a continuous ping or traceroute to api.cartesia.ai and note packet loss or spikes in latency.
3) Capture a short log window
• Collect 30–60s of logs around a failure (include timestamps). Include any lines about LLM tool execution start/end and TTS start attempts.
4) Resource checks during failure
• Run top or htop while reproducing and note CPU, memory, and load averages.
• Check for file descriptor exhaustion: ulimit -n and lsof | wc -l.
5) TTS descriptor confirmation
• Confirm the exact descriptor used in inference (format should be cartesia/sonic-3:voice_id). Paste the line (mask voice id if you want).
6) Frequency detail
• Does the failure always coincide with running that specific LLM tool? If yes, which tool or external API does the LLM call (briefly)?
If you prefer, paste:
• The TTS descriptor line and a 30–60s log snippet (timestamps + lines before/after).
Once I see the network test outputs and logs, I’ll point to the most likely root cause and exact next steps (auth/network fix, resource tuning, or adding a fallback TTS).miniature-egg-88949
12/12/2025, 5:17 AMtall-airline-16756
12/12/2025, 5:17 AMAgentSession.shutdown(drain=True) or session.aclose() after the call ends so the agent drains audio and closes I/O. If you rely only on participants leaving, the agent process may remain alive.
3) Confirm room deletion/disconnect
• After call end, verify the room no longer exists in the LiveKit server. If rooms remain, resources stay allocated.
4) Monitor which process grows
• Check which process holds memory after call end: run ps aux --sort=-rss | head -n 10 or use `top`/`htop`. Tell me whether memory growth is in:
◦ the agent process,
◦ the LiveKit server process,
◦ or another helper/service (SIP gateway, media gateway).
5) Capture a short log window around call end
• Provide 30–60s of logs spanning call termination (include SIP BYE, room close, agent shutdown events). Look for shutdown, close, or error events.
6) Resource metrics to collect
• Before/during/after a call reproduce: memory RSS, process count, open file descriptors (lsof | wc -l), and ulimit -n.
7) Check for unclosed handles in your agent
• Ensure streams, sockets, file descriptors, and timers started by the agent or your tool are explicitly closed when the call ends. If you use custom LLM tool code, confirm it closes HTTP connections/streams and doesn’t keep references to audio buffers.
8) Short-term mitigation
• If you cannot immediately find the leak, restart the agent process after call end as a temporary guardrail to free memory.
If you can answer these now it’ll narrow the root cause:
• Which method do you use to terminate calls (DeleteRoom, SIP BYE, participants leaving)?
• Which process shows the memory increase?
• Attach the TTS descriptor line and a 30–60s log snippet (mask secrets) covering call end + the OOM or the next plateau.
Next steps I’ll take once you share that info:
• If the agent process holds memory, I’ll walk you through checking for unclosed streams and the exact shutdown calls to add.
• If LiveKit server or SIP gateway is the culprit, I’ll guide you on room deletion checks and gateway cleanup steps.
• I’ll also show how to correlate the LLM tool execution with the TTS APIConnectionError if they occur together.
Would you like to start by telling me which termination method you use and which process shows memory growth?
Sources: Job lifecycle | LiveKit docs | Events and error handling | LiveKit docs