> For a complete documentation index, fetch https://docs.voximplant.ai/llms.txt

# Gemini

Gemini provides a VoxEngine client for connecting a call or media unit to the Google Gemini Live API over WebSocket.

Use `Gemini.createLiveAPIClient(...)` to create a `LiveAPIClient` for the current scenario.

## Related guides

Learn how Gemini Live fits into a VoxEngine call flow.

## Contents

* &#x20;[Usage](#usage): required module import and basic flow.
* &#x20;[Factory functions](#factory-functions): create the Gemini Live client.
* &#x20;[Methods](#methods): media, response, and connection control methods.
* &#x20;[Events](#events): WebSocket media bridge events.
* &#x20;[LiveAPIEvents](#liveapievents): Gemini Live API event names and payload fields.

## Usage

Add the module before using the namespace:

```js
require(Modules.Gemini);
```

Create the client, bridge media, and listen for Live API events.

## Factory functions

### &#x20;createLiveAPIClient

Creates a [Gemini.LiveAPIClient](/api-reference/voxengine/gemini#liveapiclient) instance.

```ts
createLiveAPIClient(parameters: LiveAPIClientParameters): Promise<LiveAPIClient>
```

**Parameters**

| Parameter    | Type                                               | Req. | Description |
| ------------ | -------------------------------------------------- | ---- | ----------- |
| `parameters` | <code>LiveAPI<wbr />Client<wbr />Parameters</code> | ✓    |             |

**Returns**

| Type                                 | Description                                                        |
| ------------------------------------ | ------------------------------------------------------------------ |
| <code>Promise\<LiveAPIClient></code> | Resolves to the [`Gemini.LiveAPIClient`](#liveapiclient) instance. |

## LiveAPIClient

## Methods

### &#x20;addEventListener

Adds a handler for the specified [Gemini.LiveAPIEvents](/api-reference/voxengine/gemini#liveapievents) or [Gemini.Events](/api-reference/voxengine/gemini#events) event. Use only functions as handlers; anything except a function leads to the error and scenario termination when a handler is called.

```ts
addEventListener(event: Events | LiveAPIEvents | string, callback: (event: object) => any): void
```

**Parameters**

| Parameter  | Type                                                  | Req. | Description                                   |
| ---------- | ----------------------------------------------------- | ---- | --------------------------------------------- |
| `event`    | <code>Events \| LiveAPI<wbr />Events \| string</code> | ✓    | Event constant or event name to subscribe to. |
| `callback` | <code>(event: object) => any</code>                   | ✓    | Function called when the event is emitted.    |

**Returns**

| Type   | Description              |
| ------ | ------------------------ |
| `void` | Does not return a value. |

### &#x20;clearMediaBuffer

Clears the LiveAPI WebSocket media buffer.

```ts
clearMediaBuffer(parameters?: ClearMediaBufferParameters): void
```

**Parameters**

| Parameter    | Type                                                  | Req. | Description |
| ------------ | ----------------------------------------------------- | ---- | ----------- |
| `parameters` | <code>ClearMedia<wbr />Buffer<wbr />Parameters</code> | ✗    |             |

**Returns**

| Type   | Description              |
| ------ | ------------------------ |
| `void` | Does not return a value. |

### &#x20;close

Closes the LiveAPI connection (over WebSocket) or connection attempt.

```ts
close(): void
```

**Parameters**

This method does not accept parameters.

**Returns**

| Type   | Description              |
| ------ | ------------------------ |
| `void` | Does not return a value. |

### &#x20;id

Returns the LiveAPIClient id.

```ts
id(): string
```

**Parameters**

This method does not accept parameters.

**Returns**

| Type     | Description                 |
| -------- | --------------------------- |
| `string` | The requested string value. |

### &#x20;removeEventListener

Removes a handler for the specified [Gemini.LiveAPIEvents](/api-reference/voxengine/gemini#liveapievents) or [Gemini.Events](/api-reference/voxengine/gemini#events) event.

```ts
removeEventListener(event: Events | LiveAPIEvents | string, callback?: (event: object) => any): void
```

**Parameters**

| Parameter  | Type                                                  | Req. | Description                                   |
| ---------- | ----------------------------------------------------- | ---- | --------------------------------------------- |
| `event`    | <code>Events \| LiveAPI<wbr />Events \| string</code> | ✓    | Event constant or event name to subscribe to. |
| `callback` | <code>(event: object) => any</code>                   | ✗    | Function called when the event is emitted.    |

**Returns**

| Type   | Description              |
| ------ | ------------------------ |
| `void` | Does not return a value. |

### &#x20;sendClientContent

Transmits a LiveClientContent over the established connection.
[https://pkg.go.dev/google.golang.org/genai@v1.57.0#Session.SendClientContent](https://pkg.go.dev/google.golang.org/genai@v1.57.0#Session.SendClientContent)

```ts
sendClientContent(input: Object): void
```

**Parameters**

| Parameter | Type     | Req. | Description |
| --------- | -------- | ---- | ----------- |
| `input`   | `Object` | ✓    |             |

**Returns**

| Type   | Description              |
| ------ | ------------------------ |
| `void` | Does not return a value. |

### &#x20;sendMediaTo

Starts sending media from the LiveAPI (via WebSocket) to the media unit. LiveAPI works in real time.

```ts
sendMediaTo(mediaUnit: VoxMediaUnit, parameters?: SendMediaParameters): void
```

**Parameters**

| Parameter    | Type                                    | Req. | Description |
| ------------ | --------------------------------------- | ---- | ----------- |
| `mediaUnit`  | `VoxMediaUnit`                          | ✓    |             |
| `parameters` | <code>SendMedia<wbr />Parameters</code> | ✗    |             |

**Returns**

| Type   | Description              |
| ------ | ------------------------ |
| `void` | Does not return a value. |

### &#x20;sendRealtimeInput

Transmits a LiveClientRealtimeInput over the established connection.
[https://pkg.go.dev/google.golang.org/genai@v1.57.0#Session.SendRealtimeInput](https://pkg.go.dev/google.golang.org/genai@v1.57.0#Session.SendRealtimeInput)

```ts
sendRealtimeInput(input: Object): void
```

**Parameters**

| Parameter | Type     | Req. | Description |
| --------- | -------- | ---- | ----------- |
| `input`   | `Object` | ✓    |             |

**Returns**

| Type   | Description              |
| ------ | ------------------------ |
| `void` | Does not return a value. |

### &#x20;sendToolResponse

Transmits a LiveClientToolResponse over the established connection.
[https://pkg.go.dev/google.golang.org/genai@v1.57.0#Session.SendToolResponse](https://pkg.go.dev/google.golang.org/genai@v1.57.0#Session.SendToolResponse)

```ts
sendToolResponse(input: Object): void
```

**Parameters**

| Parameter | Type     | Req. | Description |
| --------- | -------- | ---- | ----------- |
| `input`   | `Object` | ✓    |             |

**Returns**

| Type   | Description              |
| ------ | ------------------------ |
| `void` | Does not return a value. |

### &#x20;stopMediaTo

Stops sending media from the LiveAPI (via WebSocket) to the media unit.

```ts
stopMediaTo(mediaUnit: VoxMediaUnit): void
```

**Parameters**

| Parameter   | Type           | Req. | Description |
| ----------- | -------------- | ---- | ----------- |
| `mediaUnit` | `VoxMediaUnit` | ✓    |             |

**Returns**

| Type   | Description              |
| ------ | ------------------------ |
| `void` | Does not return a value. |

### &#x20;webSocketId

Returns the LiveAPI WebSocket id.

```ts
webSocketId(): string
```

**Parameters**

This method does not accept parameters.

**Returns**

| Type     | Description                 |
| -------- | --------------------------- |
| `string` | The requested string value. |

## Events

These events describe audio received through the Gemini WebSocket media bridge.

### &#x20;WebSocketMediaStarted

Triggered when the audio stream sent by a third party through a Gemini WebSocket is started playing.

Event constant: `Events.WebSocketMediaStarted`

**Payload**

| Field                                | Type                                     | Req. | Description                                                                                                                                       |
| ------------------------------------ | ---------------------------------------- | ---- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| `client`                             | <code>LiveAPI<wbr />Client</code>        | ✓    | The [Gemini.LiveAPIClient](/api-reference/voxengine/gemini#liveapiclient) instance.                                                               |
| `tag`                                | `string`                                 | ✗    | Special tag to name audio streams sent over one WebSocket connection. With it, one can send 2 audios to 2 different media units at the same time. |
| `encoding`                           | `string`                                 | ✗    | Audio encoding formats.                                                                                                                           |
| <code>custom<wbr />Parameters</code> | <code>\{ \[key: string]: string }</code> | ✗    | Custom parameters.                                                                                                                                |

### &#x20;WebSocketMediaEnded

Triggers after the end of the audio stream sent by a third party through a Gemini WebSocket (**1 second of silence**).

Event constant: `Events.WebSocketMediaEnded`

**Payload**

| Field       | Type                                   | Req. | Description                                                                                                                                       |
| ----------- | -------------------------------------- | ---- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| `client`    | <code>LiveAPI<wbr />Client</code>      | ✓    | The [Gemini.LiveAPIClient](/api-reference/voxengine/gemini#liveapiclient) instance.                                                               |
| `tag`       | `string`                               | ✗    | Special tag to name audio streams sent over one WebSocket connection. With it, one can send 2 audios to 2 different media units at the same time. |
| `mediaInfo` | <code>WebSocket<wbr />MediaInfo</code> | ✗    | Information about the audio stream that can be obtained after the stream stops or pauses (**1 second of silence**).                               |

## LiveAPIEvents

These events mirror server messages from the Gemini Live API. The `data` field contains the provider event payload.

<a id="-unknown" />

The unknown event.

Event constant: `LiveAPIEvents.Unknown`

**Payload**

| Field    | Type                              | Req. | Description                                                                         |
| -------- | --------------------------------- | ---- | ----------------------------------------------------------------------------------- |
| `client` | <code>LiveAPI<wbr />Client</code> | ✓    | The [Gemini.LiveAPIClient](/api-reference/voxengine/gemini#liveapiclient) instance. |
| `data`   | `Object`                          | ✗    | The event's data.                                                                   |

<a id="-servercontent" />

Content generated by the model in response to client messages. [https://pkg.go.dev/google.golang.org/genai@v1.57.0#LiveServerContent](https://pkg.go.dev/google.golang.org/genai@v1.57.0#LiveServerContent)

Event constant: `LiveAPIEvents.ServerContent`

**Payload**

| Field    | Type                              | Req. | Description                                                                         |
| -------- | --------------------------------- | ---- | ----------------------------------------------------------------------------------- |
| `client` | <code>LiveAPI<wbr />Client</code> | ✓    | The [Gemini.LiveAPIClient](/api-reference/voxengine/gemini#liveapiclient) instance. |
| `data`   | `Object`                          | ✗    | The event's data.                                                                   |

<a id="-toolcall" />

Request for the client to execute the `function_calls` and return the responses with the matching `id`s. [https://pkg.go.dev/google.golang.org/genai@v1.57.0#LiveServerToolCall](https://pkg.go.dev/google.golang.org/genai@v1.57.0#LiveServerToolCall)

Event constant: `LiveAPIEvents.ToolCall`

**Payload**

| Field    | Type                              | Req. | Description                                                                         |
| -------- | --------------------------------- | ---- | ----------------------------------------------------------------------------------- |
| `client` | <code>LiveAPI<wbr />Client</code> | ✓    | The [Gemini.LiveAPIClient](/api-reference/voxengine/gemini#liveapiclient) instance. |
| `data`   | `Object`                          | ✗    | The event's data.                                                                   |

<a id="-toolcallcancellation" />

Notification for the client that a previously issued `ToolCallMessage` with the specified `id`s should have been not executed and should be cancelled. [https://pkg.go.dev/google.golang.org/genai@v1.57.0#LiveServerToolCallCancellation](https://pkg.go.dev/google.golang.org/genai@v1.57.0#LiveServerToolCallCancellation)

Event constant: `LiveAPIEvents.ToolCallCancellation`

**Payload**

| Field    | Type                              | Req. | Description                                                                         |
| -------- | --------------------------------- | ---- | ----------------------------------------------------------------------------------- |
| `client` | <code>LiveAPI<wbr />Client</code> | ✓    | The [Gemini.LiveAPIClient](/api-reference/voxengine/gemini#liveapiclient) instance. |
| `data`   | `Object`                          | ✗    | The event's data.                                                                   |

<a id="-connectorinformation" />

Contains information about connector.

Event constant: `LiveAPIEvents.ConnectorInformation`

**Payload**

| Field    | Type                              | Req. | Description                                                                         |
| -------- | --------------------------------- | ---- | ----------------------------------------------------------------------------------- |
| `client` | <code>LiveAPI<wbr />Client</code> | ✓    | The [Gemini.LiveAPIClient](/api-reference/voxengine/gemini#liveapiclient) instance. |
| `data`   | `Object`                          | ✗    | The event's data.                                                                   |