What is the procedure for me to be able to integra...
# ask-ai
r
What is the procedure for me to be able to integrate my own realtime api to livekit as an integration?
t
Thanks for reaching out, Cyrus. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m responding to your question about how to integrate your own realtime API with LiveKit as a custom integration. You can integrate your realtime API by building a LiveKit Agents plugin that implements the realtime model interface used by LiveKit’s agent framework. Below is a concise, step‑by‑step procedure to get you started and what to consider while building the plugin. 1. Understand the target: realtime model plugin • LiveKit Agents supports “realtime models” that handle bidirectional streaming of audio and text (speech-to-speech or multimodal realtime). Your plugin should implement the realtime model interface (a handler that accepts incoming audio/text streams and returns realtime audio/text responses). 1. Prepare your development environment • Choose the SDK you’ll use (Python or Node). Ensure the recommended runtime (e.g., Python ≥ 3.10 if using Python). • Install the LiveKit Agents SDK for your language. • Make your realtime API endpoint and credentials available (API key, WebSocket URL, etc.). 1. Implement the plugin core • Create a class for your realtime model (example names:
MyRealtimeModel
,
MyRealtimePlugin
). • Key capabilities to implement: ◦ Accept streaming audio input from LiveKit (convert or forward frames as required). ◦ Send audio to your realtime API (likely over WebSocket or streaming gRPC) and stream back responses. ◦ Support sending/receiving text if your API produces transcriptions or text responses. ◦ Provide configuration for voice/model parameters, authentication, and modalities (audio, text). • Use asynchronous streaming (async generators or similar) so the agent framework can read/write audio/text frames incrementally. 1. Integrate with AgentSession • Pass your plugin instance into the AgentSession where the LLM/realtime model is expected: ◦ Example (conceptual): create
AgentSession(llm=my_realtime_model_instance, ...)
. • Ensure the session can route audio from LiveKit participants into your plugin and play returned audio back into the LiveKit room. 1. Handle turn detection and modalities • If your realtime API handles turn detection, surface that behavior in your plugin. • If turn detection isn’t provided by your API, you can integrate LiveKit’s VAD/turn detection or configure STT-based turn cues. • Support both text-only and audio+text modes if useful (allow falling back to separate TTS/STT if the realtime API is audio-only or text-only). 1. Authentication & configuration • Require users to provide API keys or credentials via environment variables or configuration objects. • Expose configurable parameters (voice name, model id, sample rate, chunk size, latency/tls settings). 1. Testing • Create automated tests using LiveKit’s testing patterns: ◦ Test text-only flows for quick unit tests. ◦ Test streaming audio flows end-to-end with a test room or test harness that simulates audio frames. • Validate latency, audio quality, and that transcriptions (if any) remain time-aligned. 1. Documentation & packaging • Document installation, configuration, example usage, and supported modalities. • Publish the plugin (PyPI / npm) or provide install instructions for consumers. • Include example code showing how to instantiate the plugin and start an AgentSession. 1. Optional: contribute or share • If you want to share with the community, follow LiveKit’s plugin contribution guidance for the Agents project and include examples and tests. If you’d like, I can help next with any of the following: • A short Python or Node template for a realtime plugin that wires a WebSocket-based API into an AgentSession. • Example configuration and environment variable naming suggestions. • Guidance on testing streaming audio locally (what frames to send, simulating a LiveKit participant). Which would you like me to provide next — a code template in Python or Node, or help designing the authentication/config schema for your plugin? Sources: Realtime models overview | LiveKit Documentation | OpenAI and LiveKit partner to turn Advanced Voice into an API | Google AI and LiveKit | LiveKit Documentation | OpenAI Realtime API plugin guide | LiveKit Documentation | xAI Grok Voice Agent API plugin | LiveKit Documentation