Realtime voice is in beta and access is gated per workspace.
await client.realtime.connect() on AsyncPhaseo creates the session (POST /v1/audio/realtime/sessions), opens the relay WebSocket and returns once the relay sends relay.connected. The realtime client is async only and needs the optional websockets package:
connect() raises ImportError with that install command. The relay protocol, warnings and reason codes are described in Realtime voice sessions.
Example
connect() returned, starting with relay.connected, and iteration stops when the socket closes.
async with session: ends the call with end() when the block exits, if it hasn’t ended already.
Connect options
model(required): a realtime model ID, for exampleopenai/gpt-realtime-2.voice,instructions,provider,metadata: passed to the create-session request.connect_timeout: seconds to wait forrelay.connected. Default 30.websocket_connect: an async callable(url, subprotocols)returning a connected socket, to use another WebSocket library.
Session
Errors
If the socket closes, orend() times out, without session.ended, end() and ended raise RealtimeSessionClosedError. It has session_id, close_code, close_reason and final_bill, the request that returns the final cost once it is settled: GET /v1/generations?id=realtime%3A<session_id>. realtime_final_bill(session_id) builds the same request.
connect() raises if the relay ends the session before it connects, and TimeoutError if relay.connected doesn’t arrive in time.