Skip to main content
Realtime voice is in beta and access is gated per workspace.
Method: client.realtime.connect() creates the session (POST /v1/audio/realtime/sessions), opens the relay WebSocket and resolves once the relay sends relay.connected. It sends your API key, so call it on your server only. Node.js 22 or later has a global WebSocket; on older runtimes, install the ws package or pass your own constructor as webSocket. For a call that runs in the browser, create the session on your server and open the socket in the browser with connectRealtimeSession(). It takes the session your server created, including its client_secret, which works only for that one session, and never needs the API key. Browser calls shows both halves. The relay protocol, warnings and reason codes are described in Realtime voice sessions.

Example

To read every event instead, iterate the session. Iteration stops when the socket closes.

Browser calls

Never put a Phaseo API key in browser code. On your server, create the session with client.realtime.createSession(), which takes the same model, voice, instructions, provider and metadata options as connect(), and return the response to your page:
In the browser, join the session with connectRealtimeSession(). It opens the relay with the session’s client_secret and returns the same session object as connect():
connectRealtimeSession(info, options) accepts webSocket and connectTimeoutMs like connect(), plus baseUrl (default https://api.phaseo.app/v1) if you use a regional endpoint.

Connect options

  • model (required): a realtime model ID, for example openai/gpt-realtime-2.
  • voice, instructions, provider, metadata: passed to the create-session request.
  • webSocket: a WebSocket constructor to use instead of the global one.
  • connectTimeoutMs: how long to wait for relay.connected. Default 30 seconds.

Session

Errors

If the socket closes, or end() times out, without session.ended, end() and ended reject with RealtimeSessionClosedError. It has sessionId, closeCode, closeReason and finalBill, the request that returns the final cost once it is settled: GET /v1/generations?id=realtime%3A<session_id>. realtimeFinalBill(sessionId) builds the same request. connect() rejects if the relay ends the session before it connects or if relay.connected doesn’t arrive in time.
Last modified on October 28, 2026