Experimental
Experimental
Establishes a connection to the specified model with the given configuration and returns a Session object representing that connection.
Built-in MCP support is an experimental feature, may change in future versions.
The parameters for establishing a connection to the model.
A live session.
let model: string;
if (GOOGLE_GENAI_USE_VERTEXAI) {
model = 'gemini-2.0-flash-live-preview-04-09';
} else {
model = 'gemini-2.0-flash-live-001';
}
const session = await ai.live.connect({
model: model,
config: {
responseModalities: [Modality.AUDIO],
},
callbacks: {
onopen: () => {
console.log('Connected to the socket.');
},
onmessage: (e: MessageEvent) => {
console.log('Received message from the server: %s\n', debug(e.data));
},
onerror: (e: ErrorEvent) => {
console.log('Error occurred: %s\n', debug(e.error));
},
onclose: (e: CloseEvent) => {
console.log('Connection closed.');
},
},
});
Live class encapsulates the configuration for live interaction with the Generative Language API. It embeds ApiClient for general API settings.