Realtime Session
[BETA] Modules concerning the realtime session modules to interact with realtime session models.
GoogleRealtimeSession(model_name, api_key=None, credentials_path=None, project_id=None, location='us-central1', tools=None, config=None)
Bases: BaseRealtimeSession
[BETA] A realtime session module to interact with Gemini Live models.
Warning
The 'GoogleRealtimeSession' class is currently in beta and may be subject to changes in the future. It is intended only for quick prototyping in local environments. Please avoid using it in production environments.
Attributes:
| Name | Type | Description |
|---|---|---|
model_name |
str
|
The name of the language model. |
client_params |
dict[str, Any]
|
The Google client instance init parameters. |
config |
LiveConnectConfig
|
The configuration for the realtime session. |
tool_dict |
dict[str, Tool]
|
A dictionary of tools provided to the model. |
Authentication
The GoogleRealtimeSession can use either Google Gen AI or Google Vertex AI.
Google Gen AI is recommended for quick prototyping and development. It requires a Gemini API key for authentication.
Usage example:
realtime_session = GoogleRealtimeSession(
model_name="gemini-2.5-flash-native-audio-preview-12-2025",
api_key="your_api_key"
)
Google Vertex AI is recommended to build production-ready applications. It requires a service account JSON file for authentication.
Usage example:
realtime_session = GoogleRealtimeSession(
model_name="gemini-2.5-flash-native-audio-preview-12-2025",
credentials_path="path/to/service_account.json"
)
If neither api_key nor credentials_path is provided, Google Gen AI will be used by default.
The GOOGLE_API_KEY environment variable will be used for authentication.
Examples:
Basic usage:
The GoogleRealtimeSession can be used as started as follows:
python
realtime_session = GoogleRealtimeSession(model_name="gemini-live-2.5-flash-preview")
await realtime_session.invoke()
Tool calling:
The GoogleRealtimeSession can call provided tools to perform certain tasks.
This feature can be enabled by providing a list of Tool objects to the tools parameter.
Usage example:
```python
tools = [get_weather, get_temperature]
realtime_session = GoogleRealtimeSession(model_name="gemini-live-2.5-flash-preview", tools=tools)
await realtime_session.start()
```
Custom IO streamers:
The GoogleRealtimeSession can be used with custom IO streamers.
python
input_streamers = [KeyboardInputStreamer(), LinuxMicInputStreamer()]
output_streamers = [ConsoleOutputStreamer(), LinuxSpeakerOutputStreamer()]
realtime_session = GoogleRealtimeSession(model_name="gemini-live-2.5-flash-preview")
await realtime_session.start(input_streamers=input_streamers, output_streamers=output_streamers)
In the above example, we added a capability to use a Linux system microphone and speaker,
allowing realtime audio input and output to the model.
Initializes a new instance of the GoogleRealtimeChat class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
The name of the model to use. |
required |
api_key
|
str | None
|
Required for Google Gen AI authentication. Cannot be used together
with |
None
|
credentials_path
|
str | None
|
Required for Google Vertex AI authentication. Path to the service
account credentials JSON file. Cannot be used together with |
None
|
project_id
|
str | None
|
The Google Cloud project ID for Vertex AI. Only used when authenticating
with |
None
|
location
|
str
|
The location of the Google Cloud project for Vertex AI. Only used when
authenticating with |
'us-central1'
|
tools
|
list[Tool] | None
|
Tools provided to the model to enable tool calling. Defaults to None. |
None
|
config
|
dict[str, Any] | None
|
Additional configuration for the realtime session. Defaults to None. |
None
|
Note
If neither api_key nor credentials_path is provided, Google Gen AI will be used by default.
The GOOGLE_API_KEY environment variable will be used for authentication.
LiveKitRealtimeSession(url, api_key=None, api_secret=None, room_name=None, identity=None)
Bases: BaseRealtimeSession
[BETA] A realtime session module to interact with LiveKit services.
Warning
The 'LiveKitRealtimeSession' class is currently in beta and may be subject to changes in the future. It is intended only for quick prototyping in local environments. Please avoid using it in production environments.
Attributes:
| Name | Type | Description |
|---|---|---|
url |
str
|
The URL of the LiveKit server. |
Examples:
Basic usage:
The LiveKitRealtimeSession can be used as started as follows:
python
realtime_session = LiveKitRealtimeSession(url="ws://127.0.0.1:7880", token="...")
await realtime_session.start()
Custom IO streamers:
The LiveKitRealtimeSession can be used with custom IO streamers.
python
input_streamers = [KeyboardInputStreamer(), LinuxMicInputStreamer()]
output_streamers = [ConsoleOutputStreamer(), LinuxSpeakerOutputStreamer()]
realtime_session = LiveKitRealtimeSession(url="ws://127.0.0.1:7880", token="...")
await realtime_session.start(input_streamers=input_streamers, output_streamers=output_streamers)
In the above example, we added a capability to use a Linux system microphone and speaker,
allowing realtime audio input and output to the model.
Initializes a new instance of the LiveKitRealtimeSession class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL of the LiveKit server. |
required |
api_key
|
str | None
|
The API key for authentication. Defaults to None,
in which case the |
None
|
api_secret
|
str | None
|
The API secret for authentication. Defaults to None,
in which case the |
None
|
room_name
|
str | None
|
The name of the room. Defaults to None, in which case a random UUID will be used. |
None
|
identity
|
str | None
|
The identity of the participant. Defaults to None, in which case a random UUID will be used. |
None
|