Skip to main content
Weave’s integration with OpenAI’s Realtime API allows you to automatically trace your application’s speech-to-speech interactions as they occur. You can use this to capture conversations between your agents and users to review and evaluate agent performance.

Integrate realtime traces

Weave automatically patches into the OpenAI Realtime API and only requires a few additional lines of code to start capturing audio interactions from your application. The following code imports Weave and the Realtime API integration:
Once imported into your code and executed, Weave automatically traces the interactions between the user and the OpenAI Realtime API.

Run a realtime voice assistant with the OpenAI Agents SDK

This example runs a real-time voice assistant that streams microphone audio to OpenAI’s Realtime API and plays back the AI’s spoken responses through your local machine’s speaker. The application uses the OpenAI Agents SDK with RealtimeAgent and RealtimeRunner, and enables Weave tracing by patching with patch_openai_realtime(). To run the example:
  1. Start your Python environment and install the following libraries:
  2. Create a file titled weave_voice_assistant.py and add the following code to it. The highlighted lines indicate Weave’s integration in the application. The rest of the code creates the basic voice assistant app.
  3. Update the DEFAULT_WEAVE_PROJECT value with your team and project names.
  4. Set your OPENAI_API_KEY environment variable.
  5. Run the code:
Once running, press T on your keyboard to mute or unmute the mic. The assistant uses server-side voice activity detection to handle turn-taking and interruptions. As you speak to the assistant, Weave captures traces that you can explore in the Weave UI, including the audio from the session.

Run a realtime voice assistant using WebSockets

The following example connects directly to the OpenAI Realtime API over WebSockets. It streams microphone audio to the API, plays back spoken responses, and supports tool calling (weather lookups, math evaluation, code execution, and file writing). Weave traces the session the using weave.init() and patch_openai_realtime(). To run the example:
  1. Start your Python environment and install the following libraries:
  2. Create a file titled tool_definitions.py and add the following tool definitions to it. The main application imports from this module.
  3. Create a file titled weave_ws_voice_assistant.py in the same directory and add the following code to it.
  4. Update the weave.init() call with your team and project names.
  5. Set your OPENAI_API_KEY environment variable.
  6. Run the code:
Once running, press T on your keyboard to mute or unmute the mic. The assistant uses server-side voice activity detection to handle turn-taking and interruptions. As you speak to the assistant, Weave captures traces that you can explore in the Weave UI, including the audio from the session.