OpenAI Realtime API Phone Number: Connect a Voice Agent to Calls (2026)

    Two ways to put an OpenAI Realtime voice agent on a real phone number, WebSocket bridge or direct SIP, with a working Vobiz setup for inbound and outbound calls.

    OpenAI Realtime API Phone Number: Connect a Voice Agent to Calls (2026)
    Team VobizTeam Vobiz
    13 min read19 November 2026

    To give an OpenAI Realtime API voice agent a phone number, you need a telephony provider that owns the number and carries the call, plus one of two connections to OpenAI: a WebSocket media bridge, where the provider streams call audio to your server and your server relays it to the Realtime API, or direct SIP, where the provider sends the call to OpenAI's SIP endpoint and OpenAI handles the audio itself. The WebSocket bridge works for inbound and outbound calls and gives you full control of the audio. Direct SIP needs less code and takes your server out of the audio path.

    Below: both architectures, the details that decide whether the call sounds right, and a working Vobiz setup with code.

    How does an OpenAI Realtime voice agent connect to a phone call?

    The phone network carries calls as SIP and RTP, usually with the G.711 codec at 8 kHz. The Realtime API takes audio over WebSocket, WebRTC or SIP. Your telephony provider, and in one design your own server, sits between the two.

    WebSocket media bridgeDirect SIP to OpenAI
    PathCaller → provider → your server (WebSocket) → OpenAI (WebSocket)Caller → provider → OpenAI SIP endpoint
    Who touches the audioYour server, on every 20 ms frameOpenAI, with SRTP to the provider
    Your server's jobRelay audio both ways, handle barge-in, run toolsAccept the call over HTTPS, then a control WebSocket for events and tools
    Inbound callsYesYes
    Outbound callsYes, the provider dials and streams on answerDepends on the provider; most published guides cover inbound
    Audio format workYou choose and match formatsNegotiated over SIP, nothing to set
    Extra hop for audioYes, through your serverNo
    Best forCustom logic, recording or analysing the raw audio, outbound campaigns, mixing in other modelsLowest-effort inbound agents

    Neither design is provider-specific. Bandwidth documents both, and Twilio's tutorials use the bridge with Media Streams. What changes between providers is the syntax that starts the stream and the trunk settings for SIP.

    Option 1: the WebSocket media bridge

    In the bridge, your provider answers the call, fetches instructions from your answer URL, and opens a bidirectional WebSocket to your server. Your server opens a second WebSocket to wss://api.openai.com/v1/realtime?model=... and relays between them:

    • Caller to model: each audio frame from the provider becomes an input_audio_buffer.append event with a base64 audio field.
    • Model to caller: each response.output_audio.delta event from OpenAI carries base64 audio in delta, which you send back to the provider as playback.
    • Control: you configure the session with session.update, listen for input_audio_buffer.speech_started to handle interruptions, and receive tool calls as response.function_call_arguments.done.

    The cost is a server holding two WebSockets per live call. In return you see every frame, so you can record it, run a second transcription model, or swap the model without touching your numbers.

    Option 2: direct SIP to OpenAI's SIP endpoint

    OpenAI's Realtime API accepts SIP calls directly. According to OpenAI's SIP guide (checked November 2026), the setup is:

    1. Point your SIP trunk at sip:$PROJECT_ID@sip.api.openai.com;transport=tls, where $PROJECT_ID is your proj_... ID. OpenAI also lists sip-eu.api.openai.com for EU data residency and sip-in.api.openai.com for hosts in India.
    2. Signalling is SIP over TLS on port 5061. Media is SRTP. Plain UDP or TCP SIP and unencrypted RTP are not accepted.
    3. When a call arrives, OpenAI sends a realtime.call.incoming webhook to your server.
    4. Your server accepts it with POST /v1/realtime/calls/{call_id}/accept, passing the session config ("type": "realtime", the model, instructions, voice). Other call controls are /reject, /refer and /hangup.
    5. Your server opens wss://api.openai.com/v1/realtime?call_id={call_id} as a control channel for events, transcripts and tool calls. No audio flows through it.

    You don't set audio formats on a SIP call; the codec is negotiated in SIP. Transfer to a human uses SIP REFER through the /refer endpoint.

    A note on naming: OpenAI also has GPT-Live (gpt-live-1), a separate API with its own endpoint (/v1/live/sessions), events (session.input_audio.append) and SIP webhook (live.transport.incoming). Sinch's and Telnyx's recent guides target GPT-Live. This post uses the Realtime API (gpt-realtime-2.1). The architecture is the same but the event names are not, so don't mix code from the two.

    Audio format: match G.711 μ-law end to end

    Phone calls arrive as 8 kHz audio. The Realtime API accepts three input and output formats:

    Realtime formatWhat it isFits a phone call?
    {"type": "audio/pcmu"}G.711 μ-law, 8 kHzYes, no conversion
    {"type": "audio/pcma"}G.711 A-law, 8 kHzYes, no conversion
    {"type": "audio/pcm", "rate": 24000}16-bit PCM, 24 kHz onlyNeeds resampling from 8 kHz and back

    The simplest bridge asks the provider for μ-law, sets audio/pcmu for input and output in the OpenAI session, and passes payloads through untouched: no resampling, no byte swapping.

    If you use 16-bit PCM instead, you must resample 8 kHz to 24 kHz on the way in and back down on the way out, and check byte order. Vobiz, for example, sends inbound L16 in big-endian (network) byte order and expects little-endian L16 on playback. Mismatched formats show up as static, sped-up audio or silence on the first test call.

    Barge-in and interruption handling

    If the agent keeps talking over a caller, the call feels broken. On a bridge, handling interruption has three parts:

    1. Detect it. With server-side voice activity detection, OpenAI sends input_audio_buffer.speech_started when the caller starts talking. With interrupt_response enabled, OpenAI also stops generating the current response.
    2. Flush the phone's playback queue. Audio can arrive faster than real time, so seconds of speech may already be queued at the provider. Stopping the model doesn't stop that audio; tell the provider to drop it (on Vobiz, a clearAudio event).
    3. Fix the model's memory. The model assumes the caller heard the whole reply. Send conversation.item.truncate with the assistant item_id, content_index: 0 and audio_end_ms set to how much was actually played. OpenAI removes the unheard part from the conversation.

    Sending playback in small chunks (about 20 ms) keeps the flush responsive. With direct SIP, OpenAI handles all three parts because it owns the audio.

    Turn detection settings

    Turn detection lives in session.audio.input.turn_detection. The two modes are:

    • server_vad: detects speech by audio energy. Tuned with threshold, prefix_padding_ms and silence_duration_ms. OpenAI's example values are 0.5, 300 and 500.
    • semantic_vad: decides the caller has finished based on what they said, tuned with eagerness (low, medium, high, auto).

    Both accept create_response and interrupt_response. On the phone, watch silence_duration_ms: every millisecond added is dead air before the reply, while too low a value cuts callers off mid-sentence. Tune it on real phone calls, not laptop tests.

    Latency budget for a phone call

    What the caller notices is the gap between finishing a sentence and hearing the reply start. On a bridged call it is the sum of:

    LegWhat controls it
    Carrier and provider network, both directionsProvider choice, number location, where media is anchored
    Provider to your bridge serverHost your bridge close to the provider's media region
    Your server to OpenAIRegion of your server, network path to OpenAI
    End-of-turn detectionsilence_duration_ms or semantic_vad eagerness
    Model time to first audioModel choice, instruction and tool complexity

    End-of-turn detection and model choice are the legs you control most directly, so start there. Then cut avoidable network distance: for Indian callers, a bridge server in a US region adds two long round trips on every turn. Direct SIP removes the bridge legs entirely. To see what your calls actually experience, log the time between input_audio_buffer.speech_stopped and the first response.output_audio.delta, and check per-call jitter and packet loss in your CDRs.

    Transferring the call to a human

    Give the model a function tool such as transfer_to_human, then act on it when response.function_call_arguments.done arrives with that name:

    • WebSocket bridge: call your provider's call-control API to move the live call to new instructions that dial an agent. On Vobiz, that's the Transfer Call API with an aleg_url that returns a <Dial>.
    • Direct SIP: call POST /v1/realtime/calls/{call_id}/refer with a target_uri. OpenAI sends a SIP REFER down your trunk, and the provider dials the target. Check what target formats your provider accepts. Vobiz's guide uses tel:+91... targets, while Bandwidth's documentation says it only supports sip: targets for this.

    Walkthrough: an OpenAI Realtime agent on a Vobiz number

    This section builds the WebSocket bridge on Vobiz, since it covers inbound and outbound. For direct SIP on inbound calls, follow the Vobiz OpenAI Realtime integration guide, which includes a reference Python service.

    Step 1: buy a number

    In the Vobiz console, open the DID section, filter by country and buy a number (for India: 140-series, 1600-series, 92-series mobile, toll-free or local, with online KYC in minutes). Or use the API:

    curl -X POST "https://api.vobiz.ai/api/v1/Account/$AUTH_ID/numbers/purchase-from-inventory" \
      -H "X-Auth-ID: $AUTH_ID" \
      -H "X-Auth-Token: $AUTH_TOKEN" \
      -H "Content-Type: application/json" \
      -d '{"e164": "+918065551234"}'
    

    A new number takes about two minutes to register before you can call from it.

    Step 2: create an application and attach the number

    An application holds the answer URL Vobiz fetches when a call connects.

    curl -X POST "https://api.vobiz.ai/api/v1/Account/$AUTH_ID/Application/" \
      -H "X-Auth-ID: $AUTH_ID" -H "X-Auth-Token: $AUTH_TOKEN" \
      -H "Content-Type: application/json" \
      -d '{"app_name": "openai-realtime-agent",
           "answer_url": "https://agent.example.com/answer",
           "answer_method": "POST"}'
    
    # attach the number (encode + as %2B)
    curl -X POST "https://api.vobiz.ai/api/v1/Account/$AUTH_ID/numbers/%2B918065551234/application" \
      -H "X-Auth-ID: $AUTH_ID" -H "X-Auth-Token: $AUTH_TOKEN" \
      -H "Content-Type: application/json" \
      -d '{"application_id": "<app_id from the response above>"}'
    

    Step 3: return VobizXML that starts a bidirectional stream

    Your answer URL returns a <Stream> element: bidirectional="true" allows playback into the call, keepCallAlive="true" holds the call open while the stream runs, and contentType="audio/x-mulaw;rate=8000" asks for μ-law so the audio can go straight to OpenAI:

    <?xml version="1.0" encoding="UTF-8"?>
    <Response>
      <Stream bidirectional="true" keepCallAlive="true"
              contentType="audio/x-mulaw;rate=8000">wss://agent.example.com/media</Stream>
    </Response>
    

    Use wss:// with a valid certificate in production. Don't combine bidirectional="true" with audioTrack="both"; Vobiz ends the call if you do.

    Step 4: the Node.js bridge

    This minimal server (Node 18+, npm install express ws) serves the answer URL, accepts Vobiz's stream, opens a Realtime session in μ-law, relays audio both ways, handles barge-in and exposes a transfer tool.

    import express from "express";
    import http from "http";
    import { WebSocketServer, WebSocket } from "ws";
    
    const { OPENAI_API_KEY, VOBIZ_AUTH_ID, VOBIZ_AUTH_TOKEN, PUBLIC_HOST, HUMAN_NUMBER, CALLER_ID } = process.env;
    const MODEL = "gpt-realtime-2.1";
    
    const app = express();
    const xml = (res, body) =>
      res.type("application/xml").send(`<?xml version="1.0" encoding="UTF-8"?><Response>${body}</Response>`);
    
    app.post("/answer", (req, res) => xml(res,
      `<Stream bidirectional="true" keepCallAlive="true" contentType="audio/x-mulaw;rate=8000">wss://${PUBLIC_HOST}/media</Stream>`));
    
    app.post("/transfer", (req, res) => xml(res,
      `<Dial callerId="${CALLER_ID}"><Number>${HUMAN_NUMBER}</Number></Dial>`));
    
    const server = http.createServer(app);
    const wss = new WebSocketServer({ server, path: "/media" });
    
    wss.on("connection", (vobiz) => {
      let streamId, callId;
      let latestTs = 0;          // Vobiz media clock (ms)
      let replyStartTs = null;   // when the current reply started playing
      let replyItemId = null;    // assistant item currently in the playback queue
    
      const openai = new WebSocket(`wss://api.openai.com/v1/realtime?model=${MODEL}`, {
        headers: { Authorization: `Bearer ${OPENAI_API_KEY}` },
      });
      const toOpenAI = (e) => openai.readyState === WebSocket.OPEN && openai.send(JSON.stringify(e));
      const toVobiz = (e) => vobiz.readyState === WebSocket.OPEN && vobiz.send(JSON.stringify(e));
    
      openai.on("open", () => {
        toOpenAI({
          type: "session.update",
          session: {
            type: "realtime",
            instructions: "You are a friendly support agent. Keep answers short. " +
                          "If the caller asks for a person, call transfer_to_human.",
            audio: {
              input: {
                format: { type: "audio/pcmu" },
                turn_detection: { type: "server_vad", silence_duration_ms: 500,
                                  create_response: true, interrupt_response: true },
              },
              output: { format: { type: "audio/pcmu" }, voice: "alloy" },
            },
            tools: [{
              type: "function", name: "transfer_to_human",
              description: "Transfer the caller to a human agent.",
              parameters: { type: "object", properties: { reason: { type: "string" } } },
            }],
          },
        });
        toOpenAI({ type: "response.create",
                   response: { instructions: "Greet the caller and ask how you can help." } });
      });
    
      // Vobiz -> OpenAI
      vobiz.on("message", (raw) => {
        const msg = JSON.parse(raw);
        if (msg.event === "start") {
          streamId = msg.start.streamId;            // IDs are nested under "start"
          callId = msg.start.callId;
        } else if (msg.event === "media") {
          latestTs = Number(msg.media.timestamp);
          toOpenAI({ type: "input_audio_buffer.append", audio: msg.media.payload });
        } else if (msg.event === "playedStream" && msg.name === replyItemId) {
          replyItemId = null; replyStartTs = null;  // reply finished playing
        }
      });
    
      // OpenAI -> Vobiz
      openai.on("message", async (raw) => {
        const msg = JSON.parse(raw);
        switch (msg.type) {
          case "response.output_audio.delta": {
            if (replyItemId !== msg.item_id) { replyItemId = msg.item_id; replyStartTs = latestTs; }
            const audio = Buffer.from(msg.delta, "base64");
            for (let i = 0; i < audio.length; i += 160) {   // 20 ms of 8 kHz μ-law
              toVobiz({ event: "playAudio", streamId, media: {
                contentType: "audio/x-mulaw", sampleRate: 8000,
                payload: audio.subarray(i, i + 160).toString("base64") } });
            }
            break;
          }
          case "response.output_audio.done":
            toVobiz({ event: "checkpoint", streamId, name: msg.item_id });
            break;
          case "input_audio_buffer.speech_started":          // caller barged in
            if (replyItemId) {
              toVobiz({ event: "clearAudio", streamId });
              toOpenAI({ type: "conversation.item.truncate", item_id: replyItemId,
                         content_index: 0, audio_end_ms: Math.max(0, latestTs - replyStartTs) });
              replyItemId = null; replyStartTs = null;
            }
            break;
          case "response.function_call_arguments.done":
            if (msg.name === "transfer_to_human") await transfer(callId);
            break;
          case "error":
            console.error("OpenAI error", msg.error);
        }
      });
    
      vobiz.on("close", () => openai.close());   // call ended: Vobiz just closes the socket
      openai.on("close", () => vobiz.readyState === WebSocket.OPEN && vobiz.close());
    });
    
    async function transfer(callUuid) {
      await fetch(`https://api.vobiz.ai/api/v1/Account/${VOBIZ_AUTH_ID}/Call/${callUuid}/`, {
        method: "POST",
        headers: { "X-Auth-ID": VOBIZ_AUTH_ID, "X-Auth-Token": VOBIZ_AUTH_TOKEN,
                   "Content-Type": "application/json" },
        body: JSON.stringify({ legs: "aleg", aleg_url: `https://${PUBLIC_HOST}/transfer` }),
      });
    }
    
    server.listen(8080, () => console.log("listening on 8080"));
    

    A few things to check before relying on it:

    • Model and voice. Confirm both against OpenAI's models page when you build; they change more often than event shapes.
    • Truncation timing. audio_end_ms here is estimated from the Vobiz media clock since the reply started. It's close enough for most calls; the value is clamped at zero, and logging any error events after a truncate will show you if the estimate runs long.
    • End of call. Vobiz does not send a stop event when the caller hangs up; the WebSocket closes. Treat close as the end of the call, and use the hangup_url webhook as the authoritative record.
    • Transfer caller ID. Set callerId on <Dial> to a number on your Vobiz account.

    Step 5: make outbound calls with the same bridge

    Place the call with the Call API and point answer_url at the same /answer route. When the callee answers, the stream starts exactly as on an inbound call.

    curl -X POST "https://api.vobiz.ai/api/v1/Account/$AUTH_ID/Call/" \
      -H "X-Auth-ID: $AUTH_ID" -H "X-Auth-Token: $AUTH_TOKEN" \
      -H "Content-Type: application/json" \
      -d '{"from": "918065551234", "to": "919812345678",
           "answer_url": "https://agent.example.com/answer",
           "hangup_url": "https://agent.example.com/hangup",
           "machine_detection": "true"}'
    

    machine_detection flags voicemail before your agent starts talking. For India outbound, use the right number series and keep DLT registration in place.

    Choosing a provider for OpenAI Realtime phone calls

    If you're comparing Twilio alternatives for OpenAI Realtime, the pattern is the same everywhere: a bidirectional media stream, or SIP to OpenAI. The differences are carrier reach, pricing and support where your callers are.

    • Vobiz is built for voice AI with India-native carrier connectivity: SIP trunks connected to Airtel, Jio and VIL, India numbers across 140, 1600, 92-series mobile and toll-free, and flat ₹0.42/min inbound and outbound calling billed in INR with a GST invoice. Its API is near 1:1 with Plivo's, so Plivo users change little more than auth, base URL and one XML verb. It fits best when a large share of your callers are in India.
    • Twilio publishes Realtime tutorials (inbound and outbound, Node.js and Python) built on Media Streams. It's a sensible choice if your callers are mostly in the US or Europe and your team already runs on it.
    • Bandwidth documents both the WebSocket and SIP integrations; its SIP path runs on its Universal Platform and needs account enablement.
    • Sinch and Telnyx publish guides for OpenAI's newer GPT-Live API.

    How to run this on Vobiz

    1. Sign up at the Vobiz console. Your first call can be live in about 10 minutes.
    2. Buy a number and attach it to an application, as above. Check the per-country rates on the pricing page.
    3. Pick your architecture. For the WebSocket bridge, use the Voice API and the <Stream> element. For direct SIP to OpenAI, configure an inbound SIP trunk with TLS and SRTP, following the OpenAI Realtime guide.
    4. Monitor call quality in the 43-field CDRs, which include MOS, jitter and packet loss.

    For how other agent platforms connect to phone numbers, see The Telephony Layer for AI Voice Agents and our introduction to the docs.

    FAQ

    Can I connect the OpenAI Realtime API to a phone number without writing a bridge?

    Yes, for inbound calls. Point a SIP trunk at sip:<project_id>@sip.api.openai.com over TLS on port 5061 with SRTP, and handle the realtime.call.incoming webhook by calling the /accept endpoint. You still need a small HTTPS service for the webhook and for tool calls, but it never handles audio.

    What audio format should I use between the phone call and the Realtime API?

    G.711 μ-law (audio/pcmu) on both input and output. Phone calls are already 8 kHz G.711, so no conversion is needed. The Realtime API's PCM option only supports 24 kHz, which means resampling in both directions.

    Does OpenAI Realtime SIP support outbound calls?

    OpenAI's SIP guide describes calls coming in to OpenAI, which you accept, reject, refer or hang up. For outbound calls, the dependable pattern is the WebSocket bridge: your provider dials the customer and starts a media stream when they answer.

    How do I stop the agent talking when the caller interrupts?

    On input_audio_buffer.speech_started, flush the provider's playback queue (clearAudio on Vobiz) and send conversation.item.truncate with the amount of audio actually played. With interrupt_response on, OpenAI stops generating the response itself.

    Is there a SIP endpoint for India?

    OpenAI's SIP documentation lists sip-in.api.openai.com for hosts in India, alongside the global and EU endpoints. Vobiz's published OpenAI guide uses the global sip.api.openai.com:5061; check OpenAI's docs for your project's eligibility before switching.