Asterisk openai realtime example

Title: Example of Asterisk + OpenAI Realtime Call Assistant

Category: API
Tags: api, realtime, speech, asterisk

Hi everyone :waving_hand:,

I’m exploring how to build a real-time call assistant using Asterisk + OpenAI Realtime SIP API.

Does anyone have a working example or guide that covers the full flow? Specifically:

  • :white_check_mark: Asterisk configuration
  • :white_check_mark: Python implementation
  • :white_check_mark: Step-by-step guide / best practices

Any resources, code snippets, or tips would be super helpful :folded_hands:

If you’re exploring Asterisk + OpenAI Realtime SIP, you might also consider checking out AVR (Agent Voice Response) — it’s an open-source framework built specifically to connect Asterisk with real-time AI voice agents.

It handles a lot of the heavy lifting for you, such as:

  • SIP routing

  • WebSocket bridging

  • Audio streaming

  • Function-call events

  • Multi-call handling

  • Integrations with Python or other backends

Many people use it as the “glue” between Asterisk and AI models because it avoids having to reinvent all the audio transport and signaling logic from scratch.

If you’re already comfortable with Asterisk, AVR fits right into the workflow: you just configure a trunk to it, and it manages the real-time interaction with the model. From there you can focus on your logic instead of low-level streaming.

If you want, I can walk you through a sample setup or provide a minimal working example.

1 Like

Thanks buddy. I have finished the project using asterisk and OpenAI with socket. OpenAI webhook for accepting call, asterisk and OpenAI realtime to audio and socket to execute function and add response to the context.

With only these I have a back office for call tracking, summaries of calls, trace tools, config for program when the service must be active or not and other features.

That’s amazing — congratulations on completing the project!

It sounds like you built a very solid architecture: Asterisk + OpenAI realtime + sockets + webhooks, plus all the surrounding back-office features like call tracking, summaries, tracing tools, and scheduling. That’s a complete, production-ready stack.

Well done — really impressive work.

If you ever feel like sharing more details with the community, I’m sure many people would find your setup valuable and inspiring.

1 Like

This is the architecture of the whole system.The challenge is in setup the asterisk, but here is the complete setup I’ve implemented: How to config asterisk to instegrate openai sip realtime · GitHub

The last challenge is to setup well the virtual machine so get secury for production but without affecting the audio and the rest of sip communication between openai sip and you asterisk. Block all you need and allow only needed entries. Here are the needed commands:


sudo iptables -A INPUT  -m state --state ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A OUTPUT -p udp --dport 5061 -j ACCEPT
sudo iptables -A INPUT  -p udp --sport 5061 -j ACCEPT
sudo iptables -A INPUT  -p udp --dport 10000:20000 -j ACCEPT
sudo iptables -A OUTPUT -p udp --sport 10000:20000 -j ACCEPT 
sudo ufw allow out 5061/udp
sudo ufw allow 10000:20000/udp
sudo ufw reload

Important: Openai webhook calls your endpoint not using the same ip, so you need to get the range so you can protect well you virtual machine where is running the asterisk. Here a list of ips: openai-crawlers-ip-ranges/openai/openai-ip-ranges-all.txt at main · FabrizioCafolla/openai-crawlers-ip-ranges · GitHub