pub struct RealtimeClient { /* private fields */ }Expand description
The main client for interacting with the OpenAI Realtime API.
Thread safety: RealtimeClient is Send but not Sync because the underlying
WebSocket stream is not Sync.
Implementations§
Source§impl RealtimeClient
impl RealtimeClient
Sourcepub async fn connect(
api_key: &str,
model: Option<&str>,
call_id: Option<&str>,
) -> Result<Self>
pub async fn connect( api_key: &str, model: Option<&str>, call_id: Option<&str>, ) -> Result<Self>
Connect to the OpenAI Realtime API.
§Errors
Returns an error if the connection fails or if the URL is invalid.
Sourcepub async fn send(&mut self, event: ClientEvent) -> Result<()>
pub async fn send(&mut self, event: ClientEvent) -> Result<()>
Send a client event to the server.
§Errors
Returns an error if serialization fails or if the WebSocket send fails.
Sourcepub async fn next_event(&mut self) -> Result<Option<ServerEvent>>
pub async fn next_event(&mut self) -> Result<Option<ServerEvent>>
Receive the next server event.
§Errors
Returns an error if deserialization fails or if the WebSocket fails.
Sourcepub fn split(self) -> (RealtimeSender, RealtimeReceiver)
pub fn split(self) -> (RealtimeSender, RealtimeReceiver)
Split the client into a sender and a receiver for concurrent usage.
Sourcepub fn unsplit(
sender: RealtimeSender,
receiver: RealtimeReceiver,
) -> Result<Self>
pub fn unsplit( sender: RealtimeSender, receiver: RealtimeReceiver, ) -> Result<Self>
Re-unify a split client.
§Errors
Returns an error if the split halves don’t match or cannot be reunited.
Auto Trait Implementations§
impl !Freeze for RealtimeClient
impl !RefUnwindSafe for RealtimeClient
impl Send for RealtimeClient
impl Sync for RealtimeClient
impl Unpin for RealtimeClient
impl !UnwindSafe for RealtimeClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more