shy-article-62777
09/02/2025, 2:55 PMtall-airline-16756
09/02/2025, 2:55 PMtall-airline-16756
09/02/2025, 2:56 PMgemini-2.5-flash and have vertexai=True set up properly.
• Optimize network proximity: Try to deploy your agent server in the same Google Cloud region as your Vertex AI endpoint (like us-central1) to keep those network delays to a minimum.
• Enable preemptive generation: If it fits your use case, turning on preemptive_generation=True can really help cut down the response time you experience.
• Avoid Gemini 2.5 Live API for function calling: Since this API is still in preview, it might cause some delays because of known issues.
• Monitor and optimize with metrics: Keep an eye on latency by using LiveKit’s metrics tools to track things like Time To First Token (TTFT) and Time To First Byte (TTFB).
Hopefully, these pointers make a difference! If you want a hand with setting any of this up or have questions, just let me know—I’m here to help.
Sources: How can I reduce latency in voice agents using STT, TTS and LLM? | Agent speech and audio | LiveKit Docs | Voice Assistants | livekit/livekit_composite | DeepWiki | Voice Assistants | livekit/livekit_composite | DeepWiki | Getting Help | livekit/livekit_composite | DeepWikishy-article-62777
09/02/2025, 3:04 PMtall-airline-16756
09/02/2025, 3:05 PMbase_url parameter. For example, if you want to try an EU endpoint, you can do it like this:
tts = elevenlabs.TTS(base_url="https://api-eu.elevenlabs.io/v1")
That said, it’s not totally clear if ElevenLabs actually offers a dedicated EU endpoint. It might be a good idea to take a peek at their API docs or reach out to their support team to double-check. If they do have one, you can definitely set LiveKit up to use it. Hope that helps!
Sources: livekit-plugins/livekit-plugins-elevenlabs/livekit/plugins/elevenlabs/tts.p... | plugins/elevenlabs/src/tts.test.ts | ElevenLabs TTS integration guide | LiveKit Docsshy-article-62777
09/02/2025, 3:30 PMtall-airline-16756
09/02/2025, 3:31 PMbase_url parameter, which lets you set a custom API endpoint—like an EU-specific one if that’s what you need. This info comes straight from LiveKit’s documentation and source code, confirming how base_url works in the ElevenLabs TTS setup.
If you have any questions or want a hand with setting it up, just give me a shout. I’m here to help!shy-article-62777
09/02/2025, 9:03 PMConcurrencyLimit table)
- Using request_fnc in WorkerOptions to intercept jobs and enforce limits
- Atomic increment/decrement via PostgreSQL for slot reservation/release
Current Implementation:
python
# In WorkerOptions
request_fnc=concurrency_request_guard
async def concurrency_request_guard(req):
# Only limit VOICE mode (chat bypasses)
if interaction_mode != "VOICE":
return await req.accept()
# Try to reserve slot atomically
if await try_reserve_voice_slot(user_id):
return await req.accept()
else:
return await req.reject()
# On session end via shutdown callback
async def _release_slot_callback():
await release_voice_slot(user_id)
ctx.add_shutdown_callback(_release_slot_callback)
Questions:
1. Is request_fnc the recommended approach for concurrency limiting? Or should we be using `load_fnc`/`load_threshold` instead?
2. WebRTC Preview Calls Issue: We generate temporary tokens for "test agent" calls via our preview API:
typescript
// Preview API generates token with metadata
metadata: {
voice_agent_id: agentId,
customer_id: session.user.id, // Same user making preview
direction: "PREVIEW"
}
Problem: Preview calls consume concurrency slots but users can't easily "hang up" WebRTC calls (browser refresh, tab close, etc.), leading to leaked slots that only get cleaned up by our cron job.
Should preview/test calls:
- A) Bypass concurrency limits entirely?
- B) Have separate preview-specific limits?
- C) Use shorter TTL tokens + aggressive cleanup?
- D) Different approach altogether?
3. Cleanup Robustness: We use a two-tier fallback (connection pool → direct connection) in shutdown callbacks, but still worry about edge cases. Any LiveKit-native ways to ensure cleanup happens?
4. Alternative Patterns: Are there other concurrency patterns you'd recommend? We've seen some folks use Redis, others use worker-level limits - curious what scales best.
Context:
- ~100 concurrent users per worker instance
- Mix of long SIP calls (5-30min) and short WebRTC previews (30sec-2min)
- Multi-region deployment planned
Any insights would be hugely appreciated! 🙏