docs-devsite/ai.livesession.md
Project: /docs/reference/js/_project.yaml Book: /docs/reference/_book.yaml page_type: reference
{% comment %} DO NOT EDIT THIS FILE! This is generated by the JS SDK team, and any local changes will be overwritten. Changes should be made in the source code at https://github.com/firebase/firebase-js-sdk {% endcomment %}
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()<!-- -->.
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.
<b>Signature:</b>
export declare class LiveSession
| Property | Modifiers | Type | Description |
|---|---|---|---|
| inConversation | boolean | <b><i>(Public Preview)</i></b> Indicates whether this Live session is being controlled by an <code>AudioConversationController</code>. | |
| isClosed | boolean | <b><i>(Public Preview)</i></b> Indicates whether this Live session is closed. |
| Method | Modifiers | Description |
|---|---|---|
| close() | <b><i>(Public Preview)</i></b> Closes this session. All methods on this session will throw an error once this resolves. | |
| receive() | <b><i>(Public Preview)</i></b> Yields messages received from the server. This can only be used by one consumer at a time. | |
| send(request, turnComplete) | <b><i>(Public Preview)</i></b> Sends content to the server. | |
| sendAudioRealtime(blob) | <b><i>(Public Preview)</i></b> Sends audio data to the server in realtime. | |
| sendFunctionResponses(functionResponses) | <b><i>(Public Preview)</i></b> Sends function responses to the server. | |
| sendMediaChunks(mediaChunks) | <b><i>(Public Preview)</i></b> Sends realtime input to the server. | |
| sendMediaStream(mediaChunkStream) | <b><i>(Public Preview)</i></b> | |
| sendTextRealtime(text) | <b><i>(Public Preview)</i></b> Sends text to the server in realtime. | |
| sendVideoRealtime(blob) | <b><i>(Public Preview)</i></b> Sends video data to the server in realtime. |
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<!-- -->.
<b>Signature:</b>
inConversation: boolean;
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.
<b>Signature:</b>
isClosed: boolean;
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.
<b>Signature:</b>
close(): Promise<void>;
<b>Returns:</b>
Promise<void>
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.
<b>Signature:</b>
receive(): AsyncGenerator<LiveServerContent | LiveServerToolCall | LiveServerToolCallCancellation | LiveServerGoingAwayNotice>;
<b>Returns:</b>
AsyncGenerator<LiveServerContent | LiveServerToolCall | LiveServerToolCallCancellation | LiveServerGoingAwayNotice<!-- -->>
An AsyncGenerator that yields server messages as they arrive.
If the session is already closed, or if we receive a response that we don't support.
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.
<b>Signature:</b>
send(request: string | Array<string | Part>, turnComplete?: boolean): Promise<void>;
| Parameter | Type | Description |
|---|---|---|
| request | string | Array<string | Part<!-- -->> | The message to send to the model. |
| turnComplete | boolean | Indicates if the turn is complete. Defaults to false. |
<b>Returns:</b>
Promise<void>
If this session has been closed.
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.
<b>Signature:</b>
sendAudioRealtime(blob: GenerativeContentBlob): Promise<void>;
| Parameter | Type | Description |
|---|---|---|
| blob | GenerativeContentBlob | The base64-encoded PCM data to send to the server in realtime. |
<b>Returns:</b>
Promise<void>
If this session has been closed.
// const pcmData = ... base64-encoded 16-bit PCM at 16kHz little-endian.
const blob = { mimeType: "audio/pcm", data: pcmData };
liveSession.sendAudioRealtime(blob);
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.
<b>Signature:</b>
sendFunctionResponses(functionResponses: FunctionResponse[]): Promise<void>;
| Parameter | Type | Description |
|---|---|---|
| functionResponses | FunctionResponse<!-- -->[] | The function responses to send. |
<b>Returns:</b>
Promise<void>
If this session has been closed.
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.
Warning: This API is now obsolete.
Use
sendTextRealtime()<!-- -->,sendAudioRealtime()<!-- -->, andsendVideoRealtime()instead.
Sends realtime input to the server.
<b>Signature:</b>
sendMediaChunks(mediaChunks: GenerativeContentBlob[]): Promise<void>;
| Parameter | Type | Description |
|---|---|---|
| mediaChunks | GenerativeContentBlob<!-- -->[] | The media chunks to send. |
<b>Returns:</b>
Promise<void>
If this session has been closed.
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.
Warning: This API is now obsolete.
Use
sendTextRealtime()<!-- -->,sendAudioRealtime()<!-- -->, andsendVideoRealtime()instead.Sends a stream of GenerativeContentBlob<!-- -->.
<b>Signature:</b>
sendMediaStream(mediaChunkStream: ReadableStream<GenerativeContentBlob>): Promise<void>;
| Parameter | Type | Description |
|---|---|---|
| mediaChunkStream | ReadableStream<GenerativeContentBlob<!-- -->> | The stream of GenerativeContentBlob to send. |
<b>Returns:</b>
Promise<void>
If this session has been closed.
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.
<b>Signature:</b>
sendTextRealtime(text: string): Promise<void>;
| Parameter | Type | Description |
|---|---|---|
| text | string | The text data to send. |
<b>Returns:</b>
Promise<void>
If this session has been closed.
liveSession.sendTextRealtime("Hello, how are you?");
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<!-- -->.
<b>Signature:</b>
sendVideoRealtime(blob: GenerativeContentBlob): Promise<void>;
| Parameter | Type | Description |
|---|---|---|
| blob | GenerativeContentBlob | The base64-encoded video data to send to the server in realtime. |
<b>Returns:</b>
Promise<void>
If this session has been closed.
// const videoFrame = ... base64-encoded JPEG data
const blob = { mimeType: "image/jpeg", data: videoFrame };
liveSession.sendVideoRealtime(blob);