RealtimeResource class

Resource for Realtime API operations.

The Realtime API enables real-time audio conversations with the model using WebSockets.

Access this resource through OpenAIClient.realtime.

Example

// Connect to a realtime session
final session = await client.realtime.connect(
  model: 'gpt-realtime-2',
);

// Listen for events
session.events.listen((event) {
  if (event is ResponseTextDeltaEvent) {
    stdout.write(event.delta);
  }
});

// Send a user text message and let the model respond
session.sendUserMessage('Say hello');

// Or stream audio bytes (24 kHz PCM16 mono for realtime sessions)
session.appendAudioBytes(audioBytes);

// Close when done
await session.close();
Inheritance

Constructors

RealtimeResource({required OpenAIConfig config, required Client httpClient, required InterceptorChain interceptorChain, required RequestBuilder requestBuilder, void ensureNotClosed()?})
Creates a RealtimeResource.

Properties

config OpenAIConfig
Client configuration.
finalinherited
ensureNotClosed → void Function()?
Callback to check if the client has been closed.
finalinherited
hashCode int
The hash code for this object.
no setterinherited
httpClient → Client
HTTP client for making requests.
finalinherited
interceptorChain InterceptorChain
Interceptor chain for request/response processing.
finalinherited
requestBuilder → RequestBuilder
Request builder for constructing HTTP requests.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
streamClientFactory → Client Function()?
Factory for creating dedicated HTTP clients for streaming requests.
finalinherited

Methods

connect({required String model, RealtimeSessionCreateRequest? config}) Future<RealtimeConnection>
Connects to a realtime session.
connectTranslation({required String model, RealtimeTranslationSessionUpdateRequest? config}) Future<RealtimeTranslationConnection>
Connects to a Realtime translation session.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited