New Tool Radar

AI Agents & Automation

How to Build a Realtime Voice Agent With the OpenAI Agents SDK

Build a realtime voice agent with the OpenAI Agents SDK so callers can speak to it and hear it answer.

Schematic with three steps: Create the RealtimeAgent with short instructions; Open a RealtimeSession and connect; Test a spoken question and an interruption.

The OpenAI Agents SDK supports realtime voice agents: a RealtimeAgent inside a RealtimeSession, speaking through the Realtime API with automatic interruption detection and tools the agent can call while it talks. A voice agent is not a text agent with audio bolted on: keep its instructions short, because long spoken answers are hard to follow, and give it tools for the facts it must not guess. Keep your main API key on the server and use short-lived session tokens for the browser.

What you need

  • Python or TypeScript with the Agents SDK installed and an API key
  • A narrow job for the voice agent, such as answering opening-hours questions
  • A way to serve the session, such as a small web page or a phone bridge

Step 1: Create the RealtimeAgent with short instructions

Create a RealtimeAgent with a name, a short instruction set and the tools it needs. Write the instructions for speech: short answers, one idea at a time, and ask for the missing detail instead of guessing.

Step 2: Open a RealtimeSession and connect

Create a RealtimeSession with the agent and connect it over the transport you chose, such as WebRTC in a browser. Confirm the session connects and the agent speaks first or waits, as you configured it.

Step 3: Test a spoken question and an interruption

Ask a spoken question and confirm the agent answers from its tools, then interrupt it mid-answer and confirm it stops and listens. If it talks over you, the interruption detection is not working as configured.

Worked example: synthetic voice test

The table below is a synthetic example. It shows the expected result of the voice agent; no session was opened.

Check Expected Result
Session connects Yes Pass
Spoken question answered Yes Pass
Interruption stops the agent Yes Pass
Answer is short and spoken clearly Yes Pass

Expected result (UNTESTED). the session connects, the agent answers the spoken question briefly, and an interruption stops it mid-answer. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • Never send your main API key to the browser; generate short-lived session tokens server side.
  • Realtime agents do not support structured outputs, so do not design a voice flow that needs one.
  • Keep voice instructions short, because a long spoken answer is hard to follow and easy to interrupt.

Sources

See all