LiveKit is an open-source platform for building real-time audio and video applications with AI agents. With TrueFoundry AI Gateway integration, you can route your LiveKit AI agent requests through the Gateway for enhanced security, cost tracking, and access controls.
Real-Time Multimodal AI Agents: LiveKit enables building conversational AI experiences with sub-100ms latency for voice and video interactions. Stream audio and video between AI models and users in real-time, creating natural, responsive AI agent conversations with minimal delay.
Scalable WebRTC Infrastructure: It can handle everything from small applications to enterprise-scale deployments with thousands of concurrent participants. The platform provides robust networking with speaker detection, simulcast, and end-to-end encryption.
Comprehensive SDK Ecosystem: Offers modern, full-featured client SDKs across all major platforms with consistent APIs and extensive documentation. The platform includes first-class support for integrating AI models, STT, TTS, and real-time APIs, making it easy to build sophisticated AI-powered applications.
# TrueFoundry ConfigurationOPENAI_API_KEY=<Your TrueFoundry API Key>TRUEFOUNDRY_BASE_URL=<Your TrueFoundry Gateway URL>TRUEFOUNDRY_MODEL_ID=<Your TrueFoundry Model ID># Third-party ServicesDEEPGRAM_API_KEY=<Your Deepgram API Key>CARTESIA_API_KEY=<Your Cartesia API Key># LiveKit ConfigurationLIVEKIT_API_KEY=<Your LiveKit API Key>LIVEKIT_API_SECRET=<Your LiveKit API Secret>LIVEKIT_URL=<Your LiveKit Server URL>
You will get your API key, base URL, and model name directly from the unified code snippet above in the TrueFoundry playground. Copy these values into your .env file as shown.
Create a simple LiveKit agent that uses TrueFoundry’s AI Gateway:
Copy
Ask AI
import osfrom dotenv import load_dotenvfrom livekit import agentsfrom livekit.agents import AgentSession, Agent, RoomInputOptionsfrom livekit.plugins import ( openai, cartesia, deepgram, silero,)load_dotenv()class TrueFoundryAssistant(Agent): def __init__(self) -> None: super().__init__( instructions="You are a helpful AI assistant powered by TrueFoundry. " "You can help with questions, provide information, and have natural conversations. " "Keep your responses conversational and helpful." )async def entrypoint(ctx: agents.JobContext): # Create session with TrueFoundry Gateway integration session = AgentSession( stt=deepgram.STT( model="nova-2", language="en" ), llm=openai.LLM( model=os.getenv("TRUEFOUNDRY_MODEL_ID", "openai-main/gpt-4o"), api_key=os.getenv("OPENAI_API_KEY"), # Your TrueFoundry API Key base_url=os.getenv("TRUEFOUNDRY_BASE_URL"), # Your TrueFoundry Gateway URL temperature=0.7, ), tts=cartesia.TTS( model="sonic-english", voice="79a125e8-cd45-4c13-8a67-188112f4dd22" # Pleasant voice ), vad=silero.VAD.load( min_speaking_duration=0.3, min_silence_duration=0.8, ), ) await ctx.connect() # Start the session with the assistant await session.start( room=ctx.room, agent=TrueFoundryAssistant(), ) # Send initial greeting await session.generate_reply( instructions="Welcome the user warmly and let them know you're powered by TrueFoundry. " "Ask how you can help them today." )if __name__ == "__main__": agents.cli.run_app(agents.WorkerOptions(entrypoint_fnc=entrypoint))