stocky-tailor-95498
09/08/2025, 1:45 PMtall-airline-16756
09/08/2025, 1:45 PMtall-airline-16756
09/08/2025, 1:46 PM/chat/completions endpoint), you just need to set the base_url parameter when you initialize your LLM instance. For example, if you're working with a local Ollama server:
from livekit.plugins import openai
llm_instance = openai.LLM.with_ollama(
model="llama3.1",
base_url="<BASE_API_URL>",
)
And if you're using JavaScript:
const llm = new LLM({
model: 'llama3.1',
baseURL: '<BASE_API_URL>',
apiKey: 'ollama',
});
This approach works great with providers like Cerebras, Groq, and others that mimic OpenAI's API.
1. Customizing the LLM Node for Non-OpenAI APIs: If your LLM doesn't follow the OpenAI API format, no worries! You can customize the llm_node directly by extending the base LLM class or creating a new node to interact with your provider’s API. This gives you full control over how requests and responses are handled.
For more examples and details, feel free to check out the LiveKit GitHub repo here: LiveKit GitHub.
If you have any questions or want a hand with anything else, just let me know—I’m here to help!
Sources: Using Custom LLM Providers with the Agent | LLM Integrations | livekit/livekit_composite | DeepWiki | LiveKit integration guides | LiveKit Docs | plugins/openai/src/realtime/realtime_model.ts | Large language model (LLM) integrations | LiveKit Docsstocky-tailor-95498
09/08/2025, 1:51 PMtall-airline-16756
09/08/2025, 1:51 PMtimeout parameter is set just right when you initialize your LLM instance. If the default (like 5 seconds) feels too short for your endpoint, try increasing the read timeout a bit.
2. Verify Network Connectivity: Double-check that your custom API endpoint is reachable from where you’re running things. Tools like curl or telnet can be super helpful to test this.
3. Check Server-Side Performance: Keep an eye on the server hosting your LLM—high CPU, memory, or GPU usage can slow things down. Optimizing how your model loads and runs can make a big difference.
4. Use Retry Logic: Setting up retry logic with exponential backoff can handle those occasional hiccups. Just make sure the total retry time fits with what your app needs latency-wise.
5. Implement Error Handling: It’s a good idea to log and handle timeout errors in your code so you can spot patterns and keep improving. For example:
except asyncio.TimeoutError:
raise APITimeoutError() from None
Also, take a look at your deployment environment—sometimes burstable instance types (like t3/t4) can throttle the CPU and cause delays, so avoiding those might help.
If you want, I’m here to help you walk through any of these steps or answer any questions you have!
Sources: agents/src/llm/llm.ts | livekit-plugins/livekit-plugins-turn-detector/livekit/plugins/turn_detector... | Troubleshooting Latency and Timeout Errors with Turn Detection on AWSstocky-tailor-95498
09/09/2025, 6:14 PMtall-airline-16756
09/09/2025, 6:15 PMbase_url parameter for the LLM instance. Here’s a friendly walkthrough on how to update your script:
from livekit.agents import AgentSession
from livekit.plugins import openai
async def entrypoint(ctx: agents.JobContext):
session = AgentSession(
stt=deepgram.STT(),
llm=openai.LLM(
model="gpt-4o-mini",
base_url="https://xyz.com/abc/",
temperature=0.7
),
tts=cartesia.TTS(
model="sonic-2",
voice="28ca2041-5dda-42df-8123-f58ea9c3da00",
language="hi"
),
vad=silero.VAD.load(),
turn_detection=MultilingualModel(),
use_tts_aligned_transcript=True
)
# Add your agent logic here
Here are a few important points to keep in mind:
• Make sure to set the base_url parameter to your custom endpoint (`https://xyz.com/abc/`).
• Double-check that your endpoint is reachable and correctly set up to handle the requests.
• Feel free to tweak other parameters like temperature to best fit your needs.
If you run into any bumps or have questions along the way, please don’t hesitate to reach out—I’m here to help!
Sources: Ollama integration guide | LiveKit Docs | livekit-plugins/livekit-plugins-groq/livekit/plugins/groq/services.py | Baseten LLM integration guide | LiveKit Docs | Groq LLM integration guide | LiveKit Docs | Groq LLM integration guide | LiveKit Docsstocky-tailor-95498
09/09/2025, 6:16 PMtall-airline-16756
09/09/2025, 6:16 PM.env file, you can add this:
CUSTOM_LLM_API_BASE_URL=https://xyz.com/abc/
After that, you can update your script to load this value dynamically like this:
import os
from livekit.agents import AgentSession
from livekit.plugins import openai
async def entrypoint(ctx: agents.JobContext):
session = AgentSession(
stt=deepgram.STT(),
llm=openai.LLM(
model=\"gpt-4o-mini\",
base_url=os.getenv(\"CUSTOM_LLM_API_BASE_URL\"),
temperature=0.7
),
tts=cartesia.TTS(
model=\"sonic-2\",
voice=\"28ca2041-5dda-42df-8123-f58ea9c3da00\",
language=\"hi\"
),
vad=silero.VAD.load(),
turn_detection=MultilingualModel(),
use_tts_aligned_transcript=True
)
# Add your agent logic here
This way, your API endpoint stays protected, and you can easily update it anytime without touching the code. If you have any questions or need a hand with this, feel free to ask—I’m here to help!stocky-tailor-95498
09/09/2025, 6:17 PMtall-airline-16756
09/09/2025, 6:18 PM.env file, please add the following:
CUSTOM_LLM_API_BASE_URL=https://xyz.com/abc/
CUSTOM_LLM_API_KEY=your_api_key_here
2. Then, update your script to load these values dynamically like this:
import os
from livekit.agents import AgentSession
from livekit.plugins import openai
async def entrypoint(ctx: agents.JobContext):
session = AgentSession(
stt=deepgram.STT(),
llm=openai.LLM(
model="gpt-4o-mini",
base_url=os.getenv("CUSTOM_LLM_API_BASE_URL"),
api_key=os.getenv("CUSTOM_LLM_API_KEY"),
temperature=0.7
),
tts=cartesia.TTS(
model="sonic-2",
voice="28ca2041-5dda-42df-8123-f58ea9c3da00",
language="hi"
),
vad=silero.VAD.load(),
turn_detection=MultilingualModel(),
use_tts_aligned_transcript=True
)
# Add your agent logic here
Just a few key things to keep in mind:
• CUSTOM_LLM_API_BASE_URL should be the URL of your custom endpoint.
• CUSTOM_LLM_API_KEY is the API key you’ll use to authenticate with your custom endpoint.
• Make sure your custom endpoint is set up to accept the API key in the right way, like through a header or a query parameter.
If you run into any questions or need a hand with anything else, please don’t hesitate to reach out—I’m here to help!stocky-tailor-95498
09/09/2025, 6:20 PMtall-airline-16756
09/09/2025, 6:21 PM.env file, please include:
CUSTOM_LLM_API_BASE_URL=https://xyz.com/abc/
CUSTOM_LLM_API_KEY=your_api_key_here
2. Then, update your script to load these values dynamically like this:
import os
from livekit.agents import AgentSession
from livekit.plugins import openai
async def entrypoint(ctx: agents.JobContext):
session = AgentSession(
stt=deepgram.STT(),
llm=openai.LLM(
model="gpt-4o-mini", # Just replace this with the exact model name your API supports
base_url=os.getenv("CUSTOM_LLM_API_BASE_URL"),
api_key=os.getenv("CUSTOM_LLM_API_KEY"),
temperature=0.7
),
tts=cartesia.TTS(
model="sonic-2",
voice="28ca2041-5dda-42df-8123-f58ea9c3da00",
language="hi"
),
vad=silero.VAD.load(),
turn_detection=MultilingualModel(),
use_tts_aligned_transcript=True
)
# Feel free to add your agent logic here
Here are a few key points to keep in mind:
• Make sure the model parameter exactly matches the model name your API supports (like "gpt-4o-mini" or a similar one).
• Double-check that your custom endpoint is set up to handle requests for this specific model.
• Verify your API key is valid and has the right permissions to access the model you want to use.
If you have any questions or need a hand with anything else, just let me know—I’m here to help!stocky-tailor-95498
09/09/2025, 6:30 PMtall-airline-16756
09/09/2025, 6:31 PMspeed parameter when you initialize it. You have the flexibility to set the speed either as a float value between -1.0 and 1.0, or by choosing from convenient predefined levels like "fastest", "fast", "normal", "slow", or "slowest".
Here’s a simple example to get you started:
from livekit.plugins import cartesia
tts = cartesia.TTS(
model="sonic-2-2025-03-07", # Required for speed control
voice="28ca2041-5dda-42df-8123-f58ea9c3da00",
language="hi",
speed="fast" # You can also use float values like 0.8
)
And if you want to change the speed while the program is running, you can do that too with the update_options() method:
tts.update_options(speed="slow")
Just a quick note: speed control works only with the sonic-2-2025-03-07 model. If you’re using a different model, speed adjustments won’t take effect.
If you have any questions or need a hand with this, please don’t hesitate to ask. I’m here to help!
Sources: plugins/cartesia/src/models.ts | Cartesia integration guide | LiveKit Docs | examples/voice_agents/tts_text_pacing.pystocky-tailor-95498
09/09/2025, 6:35 PMtall-airline-16756
09/09/2025, 6:36 PMTimeoutError during end-of-turn (EOT) prediction and increased latency can be addressed with the following steps:
1. Check Instance Type: If you're using AWS, try to avoid burstable instance types like t3 or t4g, as they can throttle performance when CPU credits run out. Instead, using non-burstable instances like m5, c5, or c6i can help ensure more consistent performance.
2. Monitor CPU Credits: If burstable instances are your only option, keep an eye on the CPUCreditBalance metric in CloudWatch to make sure credits aren’t getting depleted. You might also consider enabling t3.unlimited mode if that fits your use case.
3. Verify Inference Runtime: It’s important to confirm that your EOT prediction inference finishes within the expected latency of 50–160ms. If you notice it consistently takes over 500ms, it might be worth investigating possible environmental issues like CPU throttling or network delays.
4. Pre-Download Model Files: To avoid any delays during initialization, make sure all required model files are pre-downloaded by running python3 your_agent.py download-files before deployment.
5. Review Timeout Settings: The default timeout for predict_end_of_turn is 3 seconds. While you can adjust this, it’s generally better to optimize your environment so inference completes within this timeframe.
6. Optimize Network Latency: If you’re using a remote EOT inference endpoint, ensuring low network latency between your agent and the endpoint can really help improve performance.
7. Monitor Metrics: Keep an eye on metrics like end_of_utterance_delay and transcription_delay to spot any bottlenecks in your audio processing pipeline.
Please feel free to reach out if you'd like any help walking through these steps—I’m here to support you!
Sources: Troubleshooting Latency and Timeout Errors with Turn Detection on AWS | livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti...stocky-tailor-95498
09/09/2025, 6:38 PMtall-airline-16756
09/09/2025, 6:39 PMprewarm function to initialize the LLM client with your custom API endpoint:
from livekit.agents import JobProcess, WorkerOptions, cli
from livekit.plugins import openai
def prewarm(proc: JobProcess):
# Initialize the LLM with your custom API endpoint
llm_instance = openai.LLM(
model="your-custom-model",
api_key="your-api-key", # if required
base_url="https://your-custom-api-endpoint.com/v1"
)
# Store the instance in userdata for reuse in the entrypoint
proc.userdata["llm"] = llm_instance
# Optionally, call prewarm on the instance if it has specific prewarming logic
llm_instance.prewarm()
2. Then, use the pre-initialized LLM in your entrypoint function like this:
async def entrypoint(ctx: JobContext):
session = AgentSession(
llm=ctx.proc.userdata["llm"],
stt=deepgram.STT(),
tts=openai.TTS(voice="your-voice"),
vad=silero.VAD.load()
)
await session.start(agent=MyAgent(), room=ctx.room)
3. Finally, run your application with prewarming enabled:
if __name__ == "__main__":
cli.run_app(
WorkerOptions(
entrypoint_fnc=entrypoint,
prewarm_fnc=prewarm,
num_idle_processes=1
)
)
Here are a few key points to keep in mind:
• The prewarm function sets up the LLM client and stores it in proc.userdata so it can be reused efficiently.
• Calling llm_instance.prewarm() makes sure any specific prewarming steps for the LLM are taken care of.
• This method helps you avoid the delay of creating the LLM client on the very first request, which means faster response times.
If you have any questions or need a hand with anything else, please don’t hesitate to ask—I’m here to help!
Sources: plugins/openai/src/realtime/realtime_model.ts | examples/other/kokoro_tts.pystocky-tailor-95498
09/09/2025, 6:43 PMstocky-tailor-95498
09/09/2025, 6:43 PMstocky-tailor-95498
09/09/2025, 6:45 PMabundant-father-33863
09/20/2025, 8:38 AM