LiveSession

@PublicPreviewAPI
classLiveSession


This class is deprecated.
The Vertex AI in Firebase SDK (firebase-vertexai) has been replaced with the FirebaseAI SDK (firebase-ai) to accommodate the evolving set of supported features and services.For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk

Represents a live WebSocket session capable of streaming content to and from the server.

Summary

Public functions

suspendUnit

Closes the client session.

Flow<LiveServerMessage>

Receives responses from the model for both streaming and standard requests.

suspendUnit
send(content: Content)

Sendsdata to the model.

suspendUnit
send(text: String)

Sends text to the model.

suspendUnit

Sends function calling responses to the model.

suspendUnit

Streams client data to the model.

suspendUnit
@RequiresPermission(value = "android.permission.RECORD_AUDIO")
startAudioConversation(
    functionCallHandler: ((FunctionCallPart)->FunctionResponsePart)?
)

Starts an audio conversation with the model, which can only be stopped usingstopAudioConversation orclose.

Unit

Stops the audio conversation with the model.

Unit

Stops receiving from the model.

Public functions

close

suspend fun close(): Unit

Closes the client session.

Once aLiveSession is closed, it can not be reopened; you'll need to start a newLiveSession.

receive

fun receive(): Flow<LiveServerMessage>

Receives responses from the model for both streaming and standard requests.

Callclose to stop receiving responses from the model.

Returns
Flow<LiveServerMessage>

AFlow which will emitLiveServerMessage from the model.

Throws
com.google.firebase.vertexai.type.SessionAlreadyReceivingException: com.google.firebase.vertexai.type.SessionAlreadyReceivingException

when the session is already receiving.

send

suspend fun send(content: Content): Unit

Sendsdata to the model.

Calling this afterstartAudioConversation will play the response audio immediately.

Parameters
content: Content

ClientContent to be sent to the model.

send

suspend fun send(text: String): Unit

Sends text to the model.

Calling this afterstartAudioConversation will play the response audio immediately.

Parameters
text: String

Text to be sent to the model.

sendFunctionResponse

suspend fun sendFunctionResponse(functionList: List<FunctionResponsePart>): Unit

Sends function calling responses to the model.

NOTE: If you're usingstartAudioConversation, the method will handle sending function responses to the model for you. You donot need to call this method in that case.

Parameters
functionList: List<FunctionResponsePart>

The list ofFunctionResponsePart instances indicating the function response from the client.

sendMediaStream

suspend fun sendMediaStream(mediaChunks: List<MediaData>): Unit

Streams client data to the model.

Calling this afterstartAudioConversation will play the response audio immediately.

Parameters
mediaChunks: List<MediaData>

The list ofMediaData instances representing the media data to be sent.

startAudioConversation

@RequiresPermission(value = "android.permission.RECORD_AUDIO")
suspend fun startAudioConversation(
    functionCallHandler: ((FunctionCallPart)->FunctionResponsePart)? = null
): Unit

Starts an audio conversation with the model, which can only be stopped usingstopAudioConversation orclose.

Parameters
functionCallHandler: ((FunctionCallPart)->FunctionResponsePart)? = null

A callback function that is invoked whenever the model receives a function call. TheFunctionResponsePart that the callback function returns will be automatically sent to the model.

stopAudioConversation

fun stopAudioConversation(): Unit

Stops the audio conversation with the model.

This only needs to be called after a previous call tostartAudioConversation.

If there is no audio conversation currently active, this function does nothing.

stopReceiving

fun stopReceiving(): Unit

Stops receiving from the model.

If this function is called during an ongoing audio conversation, the model's response will not be received, and no audio will be played; the live session object will no longer receive data from the server.

To resume receiving data, you must either handle it directly usingreceive, or indirectly by usingstartAudioConversation.

See also
close

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-21 UTC.