how to get lower latency for gemini 2.5 flash on v...
# ask-ai
s
how to get lower latency for gemini 2.5 flash on vertex ai its 1+ second now too long
t
Thanks for reaching out, A. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! To help reduce latency for Gemini 2.5 Flash on Vertex AI, here are a few friendly tips you might find useful: • Use the correct model configuration: Make sure you’re working with the model
gemini-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 | DeepWiki
s
does livekit support eu endpoint from elevenlabs tts?
t
Hey there! Just wanted to let you know that LiveKit lets you set up the ElevenLabs TTS integration with a custom API endpoint by using the
base_url
parameter. For example, if you want to try an EU endpoint, you can do it like this:
Copy code
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 Docs
s
are you sure tts elevenlabs offer baseurl parameter? what is oyur ousrce?
t
Absolutely! LiveKit's integration with ElevenLabs TTS does support a
base_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!
s
We're implementing per-user concurrency limits for our voice AI agent system and want to validate our approach + get guidance on a specific edge case. Our Current Setup: - Multi-tenant SaaS with voice agents (telephony + WebRTC) - Per-user concurrency limits stored in database (
ConcurrencyLimit
table) - Using
request_fnc
in
WorkerOptions
to intercept jobs and enforce limits - Atomic increment/decrement via PostgreSQL for slot reservation/release Current Implementation:
Copy code
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:
Copy code
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! 🙏