1.1.0 (latest) 1.0.0

    public abstract class SessionServiceClient

Reference documentation and code samples for the Gemini Enterprise for Customer Experience v1 API class SessionServiceClient.

SessionService client wrapper, for convenient use.

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> SessionServiceClient

## Inherited Members

[object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) [object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone) [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Derived Types

[SessionServiceClientImpl](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Ces.V1/latest/Google.Cloud.Ces.V1.SessionServiceClientImpl.md.txt)

## Namespace

[Google.Cloud.Ces.V1](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Ces.V1/latest/Google.Cloud.Ces.V1.md.txt)

## Assembly

Google.Cloud.Ces.V1.dll

## Remarks

Session service provides APIs for interacting with CES agents.

## Properties

### DefaultEndpoint

    public static string DefaultEndpoint { get; }

The default endpoint for the SessionService service, which is a host of "ces.googleapis.com" and a port of
443.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `string` |   |

### DefaultScopes

    public static IReadOnlyList<string> DefaultScopes { get; }

The default SessionService scopes.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `IReadOnlyListstring` |   |

**Remarks** The default SessionService scopes are:

- <https://www.googleapis.com/auth/ces>
- <https://www.googleapis.com/auth/cloud-platform>

### GrpcClient

    public virtual SessionService.SessionServiceClient GrpcClient { get; }

The underlying gRPC SessionService client

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `SessionServiceSessionServiceClient` |   |

### LocationsClient

    public virtual LocationsClient LocationsClient { get; }

The [LocationsClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Location/latest/Google.Cloud.Location.LocationsClient.md.txt) associated with this client.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `LocationsClient` |   |

### ServiceMetadata

    public static ServiceMetadata ServiceMetadata { get; }

The service metadata associated with this client type.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `ServiceMetadata` |   |

## Methods

### BidiRunSession(CallSettings, BidirectionalStreamingSettings)

    public virtual SessionServiceClient.BidiRunSessionStream BidiRunSession(CallSettings callSettings = null, BidirectionalStreamingSettings streamingSettings = null)

Establishes a bidirectional streaming connection with the CES agent.
The agent processes continuous multimodal inputs (e.g., text, audio) and
generates real-time multimodal output streams.

--- Client Request Stream ---
The client streams requests in the following order:

1. Initialization:
   The first message must contain
   \[SessionConfig\]\[google.cloud.ces.v1.BidiSessionClientMessage.config\].
   For audio sessions, this should also include
   \[InputAudioConfig\]\[google.cloud.ces.v1.SessionConfig.input_audio_config\]
   and
   \[OutputAudioConfig\]\[google.cloud.ces.v1.SessionConfig.output_audio_config\]
   to define audio processing and synthesis parameters.

2. Interaction:
   Subsequent messages stream
   \[SessionInput\]\[google.cloud.ces.v1.BidiSessionClientMessage.realtime_input\]
   containing real-time user input data.

3. Termination:
   The client should half-close the stream when there is no more user
   input. It should also half-close upon receiving
   \[EndSession\]\[google.cloud.ces.v1.BidiSessionServerMessage.end_session\]
   or \[GoAway\]\[google.cloud.ces.v1.BidiSessionServerMessage.go_away\] from
   the agent.

--- Server Response Stream ---
For each interaction turn, the agent streams messages in the following
sequence:

1. Speech Recognition (First N messages):
   Contains
   \[RecognitionResult\]\[google.cloud.ces.v1.BidiSessionServerMessage.recognition_result\]
   representing the concatenated user speech segments captured so far.
   This is only populated for audio sessions.

2. Response (Next M messages):
   Contains
   \[SessionOutput\]\[google.cloud.ces.v1.BidiSessionServerMessage.session_output\]
   delivering the agent's response in various modalities (e.g., text,
   audio).

3. Turn Completion (Final message of the turn):
   Contains
   \[SessionOutput\]\[google.cloud.ces.v1.BidiSessionServerMessage.session_output\]
   with \[turn_completed\]\[google.cloud.ces.v1.SessionOutput.turn_completed\]
   set to true. This signals the end of the current turn and includes
   \[DiagnosticInfo\]\[google.cloud.ces.v1.SessionOutput.diagnostic_info\]
   with execution details.

--- Audio Best Practices ---

1. Streaming:
   Stream \[audio data\]\[google.cloud.ces.v1.SessionInput.audio\]
   **CONTINUOUSLY**, even during silence. Recommended chunk size: 40-120ms
   (balances latency vs. efficiency).

2. Playback \& Interruption:
   Play \[audio responses\]\[google.cloud.ces.v1.SessionOutput.audio\] upon
   receipt. Stop playback immediately if an
   \[InterruptionSignal\]\[google.cloud.ces.v1.BidiSessionServerMessage.interruption_signal\]
   is received (e.g., user barge-in or new agent response).

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `callSettings` | `CallSettings` If not null, applies overrides to this RPC call. |
| `streamingSettings` | `BidirectionalStreamingSettings` If not null, applies streaming overrides to this RPC call. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `SessionServiceClientBidiRunSessionStream` | The client-server stream. |

**Example**

```cs
// Create client
SessionServiceClient sessionServiceClient = SessionServiceClient.Create();
// Initialize streaming call, retrieving the stream object
using SessionServiceClient.BidiRunSessionStream response = sessionServiceClient.BidiRunSession();

// Sending requests and retrieving responses can be arbitrarily interleaved
// Exact sequence will depend on client/server behavior

// Create task to do something with responses from server
Task responseHandlerTask = Task.Run(async () =>
{
    // Note that C# 8 code can use await foreach
    AsyncResponseStream<BidiSessionServerMessage> responseStream = response.GetResponseStream();
    while (await responseStream.MoveNextAsync())
    {
        BidiSessionServerMessage responseItem = responseStream.Current;
        // Do something with streamed response
    }
    // The response stream has completed
});

// Send requests to the server
bool done = false;
while (!done)
{
    // Initialize a request
    BidiSessionClientMessage request = new BidiSessionClientMessage
    {
        Config = new SessionConfig(),
    };
    // Stream a request to the server
    await response.WriteAsync(request);
    // Set "done" to true when sending requests is complete
}

// Complete writing requests to the stream
await response.WriteCompleteAsync();
// Await the response handler
// This will complete once all server responses have been processed
await responseHandlerTask;
```

### Create()

    public static SessionServiceClient Create()

Synchronously creates a [SessionServiceClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Ces.V1/latest/Google.Cloud.Ces.V1.SessionServiceClient.md.txt) using the default credentials, endpoint and
settings. To specify custom credentials or other settings, use [SessionServiceClientBuilder](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Ces.V1/latest/Google.Cloud.Ces.V1.SessionServiceClientBuilder.md.txt).

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `SessionServiceClient` | The created [SessionServiceClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Ces.V1/latest/Google.Cloud.Ces.V1.SessionServiceClient.md.txt). |

### CreateAsync(CancellationToken)

    public static Task<SessionServiceClient> CreateAsync(CancellationToken cancellationToken = default)

Asynchronously creates a [SessionServiceClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Ces.V1/latest/Google.Cloud.Ces.V1.SessionServiceClient.md.txt) using the default credentials, endpoint and
settings. To specify custom credentials or other settings, use [SessionServiceClientBuilder](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Ces.V1/latest/Google.Cloud.Ces.V1.SessionServiceClientBuilder.md.txt).

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `cancellationToken` | `CancellationToken` The [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken) to use while creating the client. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `TaskSessionServiceClient` | The task representing the created [SessionServiceClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Ces.V1/latest/Google.Cloud.Ces.V1.SessionServiceClient.md.txt). |

### RunSession(RunSessionRequest, CallSettings)

    public virtual RunSessionResponse RunSession(RunSessionRequest request, CallSettings callSettings = null)

Initiates a single-turn interaction with the CES agent within a session.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `request` | `RunSessionRequest` The request object containing all of the parameters for the API call. |
| `callSettings` | `CallSettings` If not null, applies overrides to this RPC call. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `RunSessionResponse` | The RPC response. |

**Example**

```cs
// Create client
SessionServiceClient sessionServiceClient = SessionServiceClient.Create();
// Initialize request argument(s)
RunSessionRequest request = new RunSessionRequest
{
    Config = new SessionConfig(),
    Inputs = { new SessionInput(), },
};
// Make the request
RunSessionResponse response = sessionServiceClient.RunSession(request);
```

### RunSessionAsync(RunSessionRequest, CallSettings)

    public virtual Task<RunSessionResponse> RunSessionAsync(RunSessionRequest request, CallSettings callSettings = null)

Initiates a single-turn interaction with the CES agent within a session.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `request` | `RunSessionRequest` The request object containing all of the parameters for the API call. |
| `callSettings` | `CallSettings` If not null, applies overrides to this RPC call. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `TaskRunSessionResponse` | A Task containing the RPC response. |

**Example**

```cs
// Create client
SessionServiceClient sessionServiceClient = await SessionServiceClient.CreateAsync();
// Initialize request argument(s)
RunSessionRequest request = new RunSessionRequest
{
    Config = new SessionConfig(),
    Inputs = { new SessionInput(), },
};
// Make the request
RunSessionResponse response = await sessionServiceClient.RunSessionAsync(request);
```

### RunSessionAsync(RunSessionRequest, CancellationToken)

    public virtual Task<RunSessionResponse> RunSessionAsync(RunSessionRequest request, CancellationToken cancellationToken)

Initiates a single-turn interaction with the CES agent within a session.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `request` | `RunSessionRequest` The request object containing all of the parameters for the API call. |
| `cancellationToken` | `CancellationToken` A [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken) to use for this RPC. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `TaskRunSessionResponse` | A Task containing the RPC response. |

**Example**

```cs
// Create client
SessionServiceClient sessionServiceClient = await SessionServiceClient.CreateAsync();
// Initialize request argument(s)
RunSessionRequest request = new RunSessionRequest
{
    Config = new SessionConfig(),
    Inputs = { new SessionInput(), },
};
// Make the request
RunSessionResponse response = await sessionServiceClient.RunSessionAsync(request);
```

### ShutdownDefaultChannelsAsync()

    public static Task ShutdownDefaultChannelsAsync()

Shuts down any channels automatically created by [Create()](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Ces.V1/latest/Google.Cloud.Ces.V1.SessionServiceClient.md.txt#Google_Cloud_Ces_V1_SessionServiceClient_Create) and
[CreateAsync(CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Ces.V1/latest/Google.Cloud.Ces.V1.SessionServiceClient.md.txt#Google_Cloud_Ces_V1_SessionServiceClient_CreateAsync_System_Threading_CancellationToken_). Channels which weren't automatically created are not
affected.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `Task` | A task representing the asynchronous shutdown operation. |

**Remarks** After calling this method, further calls to [Create()](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Ces.V1/latest/Google.Cloud.Ces.V1.SessionServiceClient.md.txt#Google_Cloud_Ces_V1_SessionServiceClient_Create) and
[CreateAsync(CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Ces.V1/latest/Google.Cloud.Ces.V1.SessionServiceClient.md.txt#Google_Cloud_Ces_V1_SessionServiceClient_CreateAsync_System_Threading_CancellationToken_) will create new channels, which could in turn be shut down
by another call to this method.

### StreamRunSession(RunSessionRequest, CallSettings)

    public virtual SessionServiceClient.StreamRunSessionStream StreamRunSession(RunSessionRequest request, CallSettings callSettings = null)

Initiates a single-turn interaction with the CES agent. Uses server-side
streaming to deliver incremental results and partial responses as they are
generated.

By default, complete responses (e.g., messages from callbacks or full LLM
responses) are sent to the client as soon as they are available. To enable
streaming individual text chunks directly from the model, set
\[enable_text_streaming\]\[google.cloud.ces.v1.SessionConfig.enable_text_streaming\]
to true.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `request` | `RunSessionRequest` The request object containing all of the parameters for the API call. |
| `callSettings` | `CallSettings` If not null, applies overrides to this RPC call. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `SessionServiceClientStreamRunSessionStream` | The server stream. |

**Example**

```cs
// Create client
SessionServiceClient sessionServiceClient = SessionServiceClient.Create();
// Initialize request argument(s)
RunSessionRequest request = new RunSessionRequest
{
    Config = new SessionConfig(),
    Inputs = { new SessionInput(), },
};
// Make the request, returning a streaming response
using SessionServiceClient.StreamRunSessionStream response = sessionServiceClient.StreamRunSession(request);

// Read streaming responses from server until complete
// Note that C# 8 code can use await foreach
AsyncResponseStream<RunSessionResponse> responseStream = response.GetResponseStream();
while (await responseStream.MoveNextAsync())
{
    RunSessionResponse responseItem = responseStream.Current;
    // Do something with streamed response
}
// The response stream has completed
```