Call2MeStart free

Custom LLM Integration

Connect your own LLM via WebSocket protocol

Advanced20 min

Implement a WebSocket server that follows the Call2Me LLM protocol.

python
import asyncio, websockets, json

async def handle_llm(websocket):
    async for message in websocket:
        data = json.loads(message)
        if data['type'] == 'conversation.item.create':
            user_message = data['item']['content'][0]['text']
            response = await your_llm.generate(user_message)
            await websocket.send(json.dumps({'type': 'response.text.delta', 'delta': response}))
            await websocket.send(json.dumps({'type': 'response.text.done'}))

async def main():
    async with websockets.serve(handle_llm, "0.0.0.0", 8080):
        await asyncio.Future()

asyncio.run(main())
Next Guide

Optimizing Latency

Continue

Need Help?

Check out our API docs or reach out to support.

Build your voice agent in 10 minutes.

No code. No credit card. Just a phone number.