> ## AI Agent Context
> Get the complete documentation index at: https://aistudio.google.com/llms.txt
> Use this file to discover all available pages.
> For the full documentation in a single file, fetch: https://aistudio.google.com/llms-full.txt

# Starting a Live session

{% callout type="note" %}
  **Preview:** The Live API is in preview.

{% /callout %}

{% mark class="http-wss" %}{% icon name="sync_alt" /%}`WSS`{% /mark %} `wss://generativelanguage.googleapis.com/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent`

A WebSocket connection establishes a session between the client and the Gemini
server. After a client initiates a new connection the session can exchange
messages with the server to:

* Send text, audio, or video to the Gemini server.
* Receive audio, text, or function call requests from the Gemini server.

{% callout type="note" %}
  The URL is for version `v1beta`.

{% /callout %}

## Session configuration  {% id="session-configuration" %}

The initial message sent after establishing the WebSocket connection sets the
session configuration, which includes the model, generation parameters, system
instructions, and tools.

You cannot update the configuration while the connection is open. However, you
can change the configuration parameters, except the model, when pausing and
resuming via the [session resumption mechanism](/api-reference/live#SessionResumptionConfig).

See the following example configuration. Note that the name casing in SDKs may
vary. You can look up the [Python SDK configuration options here](https://github.com/googleapis/python-genai/blob/main/google/genai/types.py).

```json
{
  "model": string,
  "generationConfig": {
    "candidateCount": integer,
    "maxOutputTokens": integer,
    "temperature": number,
    "topP": number,
    "topK": integer,
    "presencePenalty": number,
    "frequencyPenalty": number,
    "responseModalities": [string],
    "speechConfig": object,
    "mediaResolution": object,
    "translationConfig": object
  },
  "systemInstruction": string,
  "tools": [object]
}
```

For more information on the API field, see [generationConfig](/api-reference/generate-content).

## Send messages  {% id="send-messages" %}

To exchange messages over the WebSocket connection, the client must send a JSON
object over an open WebSocket connection. The JSON object must have
**exactly one** of the fields from the following object set:

```json
{
  "setup": BidiGenerateContentSetup,
  "clientContent": BidiGenerateContentClientContent,
  "realtimeInput": BidiGenerateContentRealtimeInput,
  "toolResponse": BidiGenerateContentToolResponse
}
```

### Supported client messages  {% id="client-messages" %}

See the supported client messages in the following table:

| Message | Description |
| --- | --- |
| [`BidiGenerateContentSetup`](/api-reference/live#BidiGenerateContentSetup) | Session configuration to be sent in the first message |
| [`BidiGenerateContentClientContent`](/api-reference/live#BidiGenerateContentClientContent) | Incremental content update of the current conversation delivered from the client |
| [`BidiGenerateContentRealtimeInput`](/api-reference/live#BidiGenerateContentRealtimeInput) | Real time audio, video, or text input |
| [`BidiGenerateContentToolResponse`](/api-reference/live#BidiGenerateContentToolResponse) | Response to a `ToolCallMessage` received from the server |

## Receive messages  {% id="receive-messages" %}

To receive messages from Gemini, listen for the WebSocket 'message' event,
and then parse the result according to the definition of the
supported server messages.

See the following:

```python
async with client.aio.live.connect(model='...', config=config) as session:
    await session.send(input='Hello world!', end_of_turn=True)
    async for message in session.receive():
        print(message)
```

Server messages may have a [`usageMetadata`](/api-reference/live#UsageMetadata) field but will
otherwise include **exactly one** of the other fields from the
[`BidiGenerateContentServerMessage`](/api-reference/live#BidiGenerateContentServerMessage)
message. (The `messageType` union is not expressed in JSON so the field will
appear at the top-level of the message.)

