RealtimeClientProtocol

RealtimeClientProtocol(*args, **kwargs)
Base class for protocol classes.
Protocol classes are defined as::
class Proto(Protocol):
def meth(self) -> int:

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).
For example::
class C:
def meth(self) -> int:
return 0
def func(x: Proto) -> int:
return x.meth()
func(C()) # Passes static type check See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures.
Protocol classes can be generic, they are defined as::
class GenProtoT:
def meth(self) -> T:
Parameters:
NameDescription
*args
**kwargs

Static Methods

get_factory

get_factory(
    llm_config: LLMConfig | dict[str, Any],
    logger: Logger,
    **kwargs: Any
) -> Callable[[], RealtimeClientProtocol] | None
Create a Realtime API client.
Parameters:
NameDescription
llm_configThe config for the client.

Type: LLMConfig | dict[str, typing.Any]
loggerThe logger to use for logging events.

Type: logging.Logger
**kwargsAdditional arguments.

Type: Any
Returns:
TypeDescription
Callable[[], RealtimeClientProtocol] | NoneRealtimeClientProtocol: The Realtime API client is returned if the model matches the pattern

Instance Methods

connect

connect(self) -> AsyncContextManager[None]

read_events

read_events(self) -> AsyncGenerator[RealtimeEvent, None]
Read events from a Realtime Client.

send_audio

send_audio(self, audio: str) -> None
Send audio to a Realtime API.
Parameters:
NameDescription
audioThe audio to send.

Type: str

send_function_result

send_function_result(
    self,
    call_id: str,
    result: str
) -> None
Send the result of a function call to a Realtime API.
Parameters:
NameDescription
call_idThe ID of the function call.

Type: str
resultThe result of the function call.

Type: str

send_text

send_text(
    self,
    *,
    role: Literal['user''assistant''system'],
    text: str
) -> None
Send a text message to a Realtime API.
Parameters:
NameDescription
roleThe role of the message.

Type: Literal[‘user’, ‘assistant’, ‘system’]
textThe text of the message.

Type: str

session_update

session_update(self, session_options: dict[str, Any]) -> None
Send a session update to a Realtime API.
Parameters:
NameDescription
session_optionsThe session options to update.

Type: dict[str, typing.Any]

truncate_audio

truncate_audio(
    self,
    audio_end_ms: int,
    content_index: int,
    item_id: str
) -> None
Truncate audio in a Realtime API.
Parameters:
NameDescription
audio_end_msThe end of the audio to truncate.

Type: int
content_indexThe index of the content to truncate.

Type: int
item_idThe ID of the item to truncate.

Type: str