> 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

#### [Gemini connector overview](/voice-ai-orchestration/gemini/overview)

Learn how Gemini Live fits into a VoxEngine call flow.

## Contents

* [Usage](#usage): required module import and basic flow.
* [Factory functions](#factory-functions): create the Gemini Live client.
* [Methods](#methods): media, response, and connection control methods.
* [Events](#events): WebSocket media bridge events.
* [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

### 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                                                        |
| ------------------------ | ------------------------------------------------------------------ |
| `Promise<LiveAPIClient>` | Resolves to the [`Gemini.LiveAPIClient`](#liveapiclient) instance. |

## LiveAPIClient

## Methods

### 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` | `(event: object) => any`                              | ✓    | Function called when the event is emitted.    |

**Returns**

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

### 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. |

### 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. |

### id

Returns the LiveAPIClient id.

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

**Parameters**

This method does not accept parameters.

**Returns**

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

### 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` | `(event: object) => any`                              | ✗    | Function called when the event is emitted.    |

**Returns**

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

### sendClientContent

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

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

**Parameters**

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

**Returns**

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

### 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. |

### sendRealtimeInput

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

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

**Parameters**

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

**Returns**

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

### sendToolResponse

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

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

**Parameters**

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

**Returns**

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

### 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. |

### 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.

### Events.WebSocketMediaStarted

Triggered when the audio stream sent by a third party through a Gemini WebSocket starts 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> | `{ [key: string]: string }`       | ✗    | Custom parameters.                                                                                                                                |

### Events.WebSocketMediaEnded

Triggered 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.

#### 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`   | <code>\{ custom<wbr />Event?: string; payload?: Object; }</code> | ✗    | The 'payload' parameter contains the event's data.                                  |

#### ServerContent

Content generated by the model in response to client messages. [https://pkg.go.dev/google.golang.org/genai@v1.71.0#LiveServerContent](https://pkg.go.dev/google.golang.org/genai@v1.71.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`   | <code>\{ custom<wbr />Event?: string; payload?: Object; }</code> | ✗    | The 'payload' parameter contains the event's data.                                  |

#### 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.71.0#LiveServerToolCall](https://pkg.go.dev/google.golang.org/genai@v1.71.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`   | <code>\{ custom<wbr />Event?: string; payload?: Object; }</code> | ✗    | The 'payload' parameter contains the event's data.                                  |

#### 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.71.0#LiveServerToolCallCancellation](https://pkg.go.dev/google.golang.org/genai@v1.71.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`   | <code>\{ custom<wbr />Event?: string; payload?: Object; }</code> | ✗    | The 'payload' parameter contains the event's data.                                  |

#### 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`   | <code>\{ custom<wbr />Event?: string; payload?: Object; }</code> | ✗    | The 'payload' parameter contains the event's data.                                  |