https://webrtchacks.com/the-unofficial-guide-to-openai-realtime-webrtc-api/ * Skip to primary navigation * Skip to main content * Skip to primary sidebar * Skip to footer webrtcHacks webrtcHacks guides and information for WebRTC developers * Home * Livestream * About + Chad Hart + Philipp Hancke * Subscribe * Merch * Contact * Show Search Search this website[ ][Search] Hide Search Guide llm, openai, realtime api with webrtc Chad Hart * March 18, 2025 The Unofficial Guide to OpenAI Realtime WebRTC API OpenAI using WebRTC in its Realtime API is obviously exciting to us here at webrtcHacks. Fippo and I were doing some blackboxing of this based on a quick sample the day of the WebRTC announcement so we could look at it in webrtc-internals and Wireshark. Some weeks later, my daughter was interested in using ChatGPT voice mode. That reminded me of the many old cardboard Google AIY Voice Kits I made with her. Could these be repurposed to use the new OpenAI Realtime API instead of Dialogflow? Adapting that OpenAI Realtime WebRTC sample to run on a Raspberry Pi was actually pretty simple. However, as I got beyond the basic "say hello to the bot", I noticed the documentation for using the Realtime API with WebRTC and Data Channels was not great. My initial attempt to vibe code something quick failed despite my Retreival-Augmented Generation (RAG) attempts with OpenAI's Realtime docs. This failure forced me to do some old-school thinking and experimentation for myself. I ended up coding this the traditional way with logs, network inspection, and trial and error. That ultimately led me to this post to document it all. In this post, I will: * Provide a step-by-step guide for using the OpenAI Realtime API with WebRTC * Highlight some best practices for working with WebRTC along the way * Comment on the messages and flows * Highlight how to use functions with the Realtime API's data channel Many thanks to pion founder and past webrtcHacks interviewee, Sean DuBois of OpenAI for his review and suggestions! I will be asking him to chat more about this. [word-image-4424-1] Live Example If you want to see what this is before reading, try it below. You must click the Settings button and paste your OpenAI key for this to work. (ToDo: better warnings in the app on that). [word-image-4424-2] This app is just an iFrame hosted from the webrtcHacks/ aiy-chatgpt-webrtc, but if you are not comfortable entering your credentials here, then clone the repo or copy & paste the code from the source into a HTML file and open it.. Open demo The Architecture & Code You can see my final example code on the repo. Some notes on this before we begin: * It is a single file example - just HTML with some vanilla JavaScript inside