> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Represents an active, real-time, bidirectional conversation with the model.

This class should only be instantiated by calling [LiveGenerativeModel.connect()](https://firebase.google.com/docs/reference/js/ai.livegenerativemodel#livegenerativemodelconnect).

The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `LiveSession` class.

**Signature:**

    export declare class LiveSession 

## Properties

| Property | Modifiers | Type | Description |
|---|---|---|---|
| [connectionPromise](https://firebase.google.com/docs/reference/js/ai.livesession#livesessionconnectionpromise) |   | Promise\<void\> | ***(Public Preview)*** Allows external code to await the opening of the WebSocket connection. |
| [inConversation](https://firebase.google.com/docs/reference/js/ai.livesession#livesessioninconversation) |   | boolean | ***(Public Preview)*** Indicates whether this Live session is being controlled by an `AudioConversationController`. |
| [isClosed](https://firebase.google.com/docs/reference/js/ai.livesession#livesessionisclosed) |   | boolean | ***(Public Preview)*** Indicates whether this Live session is closed. |

## Methods

| Method | Modifiers | Description |
|---|---|---|
| [close()](https://firebase.google.com/docs/reference/js/ai.livesession#livesessionclose) |   | ***(Public Preview)*** Closes this session. All methods on this session will throw an error once this resolves. |
| [receive()](https://firebase.google.com/docs/reference/js/ai.livesession#livesessionreceive) |   | ***(Public Preview)*** Yields messages received from the server. This can only be used by one consumer at a time. |
| [resumeSession(sessionResumption)](https://firebase.google.com/docs/reference/js/ai.livesession#livesessionresumesession) |   | ***(Public Preview)*** Resumes an existing live session with the server.This closes the current WebSocket connection and establishes a new one using the same configuration (URI, headers, model, system instruction, tools, etc.) as the original session. |
| [send(request, turnComplete)](https://firebase.google.com/docs/reference/js/ai.livesession#livesessionsend) |   | ***(Public Preview)*** Sends content to the server. |
| [sendAudioRealtime(blob)](https://firebase.google.com/docs/reference/js/ai.livesession#livesessionsendaudiorealtime) |   | ***(Public Preview)*** Sends audio data to the server in realtime. |
| [sendFunctionResponses(functionResponses)](https://firebase.google.com/docs/reference/js/ai.livesession#livesessionsendfunctionresponses) |   | ***(Public Preview)*** Sends function responses to the server. |
| [sendTextRealtime(text)](https://firebase.google.com/docs/reference/js/ai.livesession#livesessionsendtextrealtime) |   | ***(Public Preview)*** Sends text to the server in realtime. |
| [sendVideoRealtime(blob)](https://firebase.google.com/docs/reference/js/ai.livesession#livesessionsendvideorealtime) |   | ***(Public Preview)*** Sends video data to the server in realtime. |

## LiveSession.connectionPromise

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Allows external code to await the opening of the WebSocket connection.

**Signature:**

    connectionPromise: Promise<void>;

## LiveSession.inConversation

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Indicates whether this Live session is being controlled by an `AudioConversationController`.

**Signature:**

    inConversation: boolean;

## LiveSession.isClosed

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Indicates whether this Live session is closed.

**Signature:**

    isClosed: boolean;

## LiveSession.close()

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Closes this session. All methods on this session will throw an error once this resolves.

**Signature:**

    close(): Promise<void>;

**Returns:**

Promise\<void\>

## LiveSession.receive()

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Yields messages received from the server. This can only be used by one consumer at a time.

**Signature:**

    receive(): AsyncGenerator<LiveServerContent | LiveServerToolCall | LiveServerToolCallCancellation | LiveServerGoingAwayNotice | LiveSessionResumptionUpdate>;

**Returns:**

AsyncGenerator\<[LiveServerContent](https://firebase.google.com/docs/reference/js/ai.liveservercontent#liveservercontent_interface) \| [LiveServerToolCall](https://firebase.google.com/docs/reference/js/ai.liveservertoolcall#liveservertoolcall_interface) \| [LiveServerToolCallCancellation](https://firebase.google.com/docs/reference/js/ai.liveservertoolcallcancellation#liveservertoolcallcancellation_interface) \| [LiveServerGoingAwayNotice](https://firebase.google.com/docs/reference/js/ai.liveservergoingawaynotice#liveservergoingawaynotice_interface) \| [LiveSessionResumptionUpdate](https://firebase.google.com/docs/reference/js/ai.livesessionresumptionupdate#livesessionresumptionupdate_interface)\>

An `AsyncGenerator` that yields server messages as they arrive.

#### Exceptions

If the session is already closed, or if we receive a response that we don't support.

## LiveSession.resumeSession()

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Resumes an existing live session with the server.

This closes the current WebSocket connection and establishes a new one using the same configuration (URI, headers, model, system instruction, tools, etc.) as the original session.

**Signature:**

    resumeSession(sessionResumption?: SessionResumptionConfig): Promise<void>;

#### Parameters

| Parameter | Type | Description |
|---|---|---|
| sessionResumption | [SessionResumptionConfig](https://firebase.google.com/docs/reference/js/ai.sessionresumptionconfig#sessionresumptionconfig_interface) | The configuration for session resumption, such as the handle to the previous session state to restore. |

**Returns:**

Promise\<void\>

#### Exceptions

If the session resumption configuration is unsupported.

## LiveSession.send()

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Sends content to the server.

**Signature:**

    send(request: string | Array<string | Part>, turnComplete?: boolean): Promise<void>;

#### Parameters

| Parameter | Type | Description |
|---|---|---|
| request | string \| Array\<string \| [Part](https://firebase.google.com/docs/reference/js/ai#part)\> | The message to send to the model. |
| turnComplete | boolean | Indicates if the turn is complete. Defaults to false. |

**Returns:**

Promise\<void\>

#### Exceptions

If this session has been closed.

## LiveSession.sendAudioRealtime()

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Sends audio data to the server in realtime.

The server requires that the audio data is base64-encoded 16-bit PCM at 16kHz little-endian.

**Signature:**

    sendAudioRealtime(blob: GenerativeContentBlob): Promise<void>;

#### Parameters

| Parameter | Type | Description |
|---|---|---|
| blob | [GenerativeContentBlob](https://firebase.google.com/docs/reference/js/ai.generativecontentblob#generativecontentblob_interface) | The base64-encoded PCM data to send to the server in realtime. |

**Returns:**

Promise\<void\>

#### Exceptions

If this session has been closed.

### Example

    // const pcmData = ... base64-encoded 16-bit PCM at 16kHz little-endian.
    const blob = { mimeType: "audio/pcm", data: pcmData };
    liveSession.sendAudioRealtime(blob);

## LiveSession.sendFunctionResponses()

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Sends function responses to the server.

**Signature:**

    sendFunctionResponses(functionResponses: FunctionResponse[]): Promise<void>;

#### Parameters

| Parameter | Type | Description |
|---|---|---|
| functionResponses | [FunctionResponse](https://firebase.google.com/docs/reference/js/ai.functionresponse#functionresponse_interface)\[\] | The function responses to send. |

**Returns:**

Promise\<void\>

#### Exceptions

If this session has been closed.

## LiveSession.sendTextRealtime()

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Sends text to the server in realtime.

**Signature:**

    sendTextRealtime(text: string): Promise<void>;

#### Parameters

| Parameter | Type | Description |
|---|---|---|
| text | string | The text data to send. |

**Returns:**

Promise\<void\>

#### Exceptions

If this session has been closed.

### Example

    liveSession.sendTextRealtime("Hello, how are you?");

## LiveSession.sendVideoRealtime()

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Sends video data to the server in realtime.

The server requires that the video is sent as individual video frames at 1 FPS. It is recommended to set `mimeType` to `image/jpeg`.

**Signature:**

    sendVideoRealtime(blob: GenerativeContentBlob): Promise<void>;

#### Parameters

| Parameter | Type | Description |
|---|---|---|
| blob | [GenerativeContentBlob](https://firebase.google.com/docs/reference/js/ai.generativecontentblob#generativecontentblob_interface) | The base64-encoded video data to send to the server in realtime. |

**Returns:**

Promise\<void\>

#### Exceptions

If this session has been closed.

### Example

    // const videoFrame = ... base64-encoded JPEG data
    const blob = { mimeType: "image/jpeg", data: videoFrame };
    liveSession.sendVideoRealtime(blob);