pub struct RealtimeClient { /* private fields */ }Expand description
Builder for creating Realtime API connections.
§Example
use openai_tools::realtime::{RealtimeClient, Modality, Voice};
use openai_tools::common::models::RealtimeModel;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut client = RealtimeClient::new();
client
.model(RealtimeModel::GptRealtime_2025_08_28)
.modalities(vec![Modality::Text, Modality::Audio])
.voice(Voice::Alloy)
.instructions("You are a helpful assistant.");
let mut session = client.connect().await?;
// Use session...
session.close().await?;
Ok(())
}Implementations§
Source§impl RealtimeClient
impl RealtimeClient
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new RealtimeClient for OpenAI API.
Loads the API key from the OPENAI_API_KEY environment variable.
Sourcepub fn with_auth(auth: AuthProvider) -> Self
pub fn with_auth(auth: AuthProvider) -> Self
Create a new RealtimeClient with a custom authentication provider.
Sourcepub fn detect_provider() -> Result<Self>
pub fn detect_provider() -> Result<Self>
Create a new RealtimeClient by auto-detecting the provider.
Sourcepub fn with_url<S: Into<String>>(base_url: S, api_key: S) -> Self
pub fn with_url<S: Into<String>>(base_url: S, api_key: S) -> Self
Creates a new RealtimeClient with URL-based provider detection.
Sourcepub fn from_url<S: Into<String>>(url: S) -> Result<Self>
pub fn from_url<S: Into<String>>(url: S) -> Result<Self>
Creates a new RealtimeClient from URL using environment variables.
Sourcepub fn with_api_key(api_key: impl Into<String>) -> Self
👎Deprecated since 0.3.0: Use with_auth(AuthProvider::OpenAI(...)) instead
pub fn with_api_key(api_key: impl Into<String>) -> Self
Use with_auth(AuthProvider::OpenAI(...)) instead
Create a new RealtimeClient with an explicit API key.
Sourcepub fn auth(&self) -> &AuthProvider
pub fn auth(&self) -> &AuthProvider
Returns the authentication provider.
Sourcepub fn model(&mut self, model: RealtimeModel) -> &mut Self
pub fn model(&mut self, model: RealtimeModel) -> &mut Self
Set the model for the Realtime API.
§Example
use openai_tools::realtime::RealtimeClient;
use openai_tools::common::models::RealtimeModel;
let mut client = RealtimeClient::new();
client.model(RealtimeModel::GptRealtime_2025_08_28);Sourcepub fn model_id(&mut self, model_id: impl Into<String>) -> &mut Self
👎Deprecated since 0.2.0: Use model(RealtimeModel) instead for type safety
pub fn model_id(&mut self, model_id: impl Into<String>) -> &mut Self
Use model(RealtimeModel) instead for type safety
Set the model using a string ID (for backward compatibility).
Prefer using [model] with RealtimeModel enum for type safety.
Sourcepub fn modalities(&mut self, modalities: Vec<Modality>) -> &mut Self
pub fn modalities(&mut self, modalities: Vec<Modality>) -> &mut Self
Set the supported modalities.
Sourcepub fn instructions(&mut self, instructions: impl Into<String>) -> &mut Self
pub fn instructions(&mut self, instructions: impl Into<String>) -> &mut Self
Set the system instructions.
Sourcepub fn input_audio_format(&mut self, format: AudioFormat) -> &mut Self
pub fn input_audio_format(&mut self, format: AudioFormat) -> &mut Self
Set the input audio format.
Sourcepub fn output_audio_format(&mut self, format: AudioFormat) -> &mut Self
pub fn output_audio_format(&mut self, format: AudioFormat) -> &mut Self
Set the output audio format.
Sourcepub fn enable_transcription(&mut self, model: TranscriptionModel) -> &mut Self
pub fn enable_transcription(&mut self, model: TranscriptionModel) -> &mut Self
Enable input audio transcription.
Sourcepub fn transcription(&mut self, config: InputAudioTranscription) -> &mut Self
pub fn transcription(&mut self, config: InputAudioTranscription) -> &mut Self
Set input audio transcription configuration.
Sourcepub fn server_vad(&mut self, config: ServerVadConfig) -> &mut Self
pub fn server_vad(&mut self, config: ServerVadConfig) -> &mut Self
Set Server VAD turn detection.
Sourcepub fn semantic_vad(&mut self, config: SemanticVadConfig) -> &mut Self
pub fn semantic_vad(&mut self, config: SemanticVadConfig) -> &mut Self
Set Semantic VAD turn detection.
Sourcepub fn disable_turn_detection(&mut self) -> &mut Self
pub fn disable_turn_detection(&mut self) -> &mut Self
Disable turn detection (manual mode).
Sourcepub fn tools(&mut self, tools: Vec<Tool>) -> &mut Self
pub fn tools(&mut self, tools: Vec<Tool>) -> &mut Self
Set available tools for function calling.
Accepts Tool from the common module and converts to RealtimeTool.
Sourcepub fn realtime_tools(&mut self, tools: Vec<RealtimeTool>) -> &mut Self
pub fn realtime_tools(&mut self, tools: Vec<RealtimeTool>) -> &mut Self
Set available realtime tools directly.
Sourcepub fn temperature(&mut self, temp: f32) -> &mut Self
pub fn temperature(&mut self, temp: f32) -> &mut Self
Set the sampling temperature.
Sourcepub async fn connect(&self) -> Result<RealtimeSession>
pub async fn connect(&self) -> Result<RealtimeSession>
Connect to the Realtime API.
Returns a RealtimeSession for sending and receiving events.
Trait Implementations§
Source§impl Clone for RealtimeClient
impl Clone for RealtimeClient
Source§fn clone(&self) -> RealtimeClient
fn clone(&self) -> RealtimeClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more