little-king-41579
12/15/2025, 10:27 AMtall-airline-16756
12/15/2025, 10:27 AMtall-airline-16756
12/15/2025, 10:27 AMfrom livekit.agents import llm
from livekit.plugins import openai
session = AgentSession(
llm=llm.FallbackAdapter([
openai.LLM(model="gpt-4o"), # primary
openai.LLM.with_azure(model="gpt-4o", ...), # fallback
]),
)
• Failed providers are marked unhealthy and periodically rechecked.
2) Listen for ErrorEvent and handle errors programmatically
• Subscribe to the session error event to log, notify users, or trigger recovery.
• Example (Python):
@session.on("error")
def on_error(event):
if not event.error.recoverable:
# Fatal error (e.g., auth failure)
print(f"Unrecoverable error: {event.error}")
session.say("Sorry, I'm having trouble processing your request.")
else:
# Transient error (e.g., rate limit)
print(f"Transient error: {event.error}")
• Useful properties: error.recoverable, source, model_config.
3) Ensure authentication and environment variables are correct
• Set Azure keys/endpoints and API version:
AZURE_OPENAI_API_KEY=your-key
AZURE_OPENAI_ENDPOINT=<https://your-endpoint.openai.azure.com>
OPENAI_API_VERSION=2024-10-01-preview
• You can also use a Microsoft Entra ID token if needed.
Quick best-practice checklist
• Chain providers with FallbackAdapter for high availability.
• Subscribe to error events and distinguish recoverable vs unrecoverable errors.
• Inform users gracefully (e.g., session.say()).
• Validate API keys, endpoint, and API version early.
If you want, I can:
• Show a more complete code example for your language (Python or JS).
• Help design retry/backoff logic or logging strategies tailored to your app. Sources: Events and error handling | LiveKit docs | Azure OpenAI LLM plugin guide | LiveKit docs