Model
RealtimePlaybackState
Bases:TypedDict
Source code insrc/agents/realtime/model.py
current_item_idinstance-attribute
The item ID of the current item being played.
current_item_content_indexinstance-attribute
The index of the current item content being played.
RealtimePlaybackTracker
If you have custom playback logic or expect that audio is played with delays or at differentspeeds, create an instance of RealtimePlaybackTracker and pass it to the session. You areresponsible for tracking the audio playback progress and callingon_play_bytes oron_play_ms when the user has played some audio.
Source code insrc/agents/realtime/model.py
on_play_bytes
Called by you when you have played some audio.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_id | str | The item ID of the audio being played. | required |
item_content_index | int | The index of the audio content in | required |
bytes | bytes | The audio bytes that have been fully played. | required |
Source code insrc/agents/realtime/model.py
on_play_ms
Called by you when you have played some audio.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_id | str | The item ID of the audio being played. | required |
item_content_index | int | The index of the audio content in | required |
ms | float | The number of milliseconds of audio that have been played. | required |
Source code insrc/agents/realtime/model.py
on_interrupted
set_audio_format
set_audio_format(format:RealtimeAudioFormat)->NoneWill be called by the model to set the audio format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
format | RealtimeAudioFormat | The audio format to use. | required |
get_state
get_state()->RealtimePlaybackStateWill be called by the model to get the current playback state.
Source code insrc/agents/realtime/model.py
RealtimeModelListener
Bases:ABC
A listener for realtime transport events.
Source code insrc/agents/realtime/model.py
on_eventabstractmethodasync
RealtimeModelConfig
Bases:TypedDict
Options for connecting to a realtime model.
Source code insrc/agents/realtime/model.py
api_keyinstance-attribute
The API key (or function that returns a key) to use when connecting. If unset, the model willtry to use a sane default. For example, the OpenAI Realtime model will try to use theOPENAI_API_KEY environment variable.
urlinstance-attribute
The URL to use when connecting. If unset, the model will use a sane default. For example,the OpenAI Realtime model will use the default OpenAI WebSocket URL.
headersinstance-attribute
The headers to use when connecting. If unset, the model will use a sane default.Note that, when you set this, authorization header won't be set under the hood.e.g., {"api-key": "your api key here"} for Azure OpenAI Realtime WebSocket connections.
initial_model_settingsinstance-attribute
initial_model_settings:NotRequired[RealtimeSessionModelSettings]The initial model settings to use when connecting.
playback_trackerinstance-attribute
playback_tracker:NotRequired[RealtimePlaybackTracker]The playback tracker to use when tracking audio playback progress. If not set, the model willuse a default implementation that assumes audio is played immediately, at realtime speed.
A playback tracker is useful for interruptions. The model generates audio much faster thanrealtime playback speed. So if there's an interruption, its useful for the model to know howmuch of the audio has been played by the user. In low-latency scenarios, it's fine to assumethat audio is played back immediately at realtime speed. But in scenarios like phone calls orother remote interactions, you can set a playback tracker that lets the model know when audiois played to the user.
call_idinstance-attribute
Attach to an existing realtime call instead of creating a new session.
When provided, the transport connects using thecall_id query string parameter rather than amodel name. This is used for SIP-originated calls that are accepted via the Realtime Calls API.
RealtimeModel
Bases:ABC
Interface for connecting to a realtime model and sending/receiving events.
Source code insrc/agents/realtime/model.py
connectabstractmethodasync
connect(options:RealtimeModelConfig)->Noneadd_listenerabstractmethod
add_listener(listener:RealtimeModelListener)->Noneremove_listenerabstractmethod
remove_listener(listener:RealtimeModelListener)->None