Table of Contents

Class GeminiChatRequest

Request to generate a response from the model.

public class GeminiChatRequest : IGeminiStreamablePostRequest<GeminiChatResponse>, IGeminiPostRequest, IGeminiRequest
Inheritance
GeminiChatRequest
Implements
Extension Methods

Constructors

GeminiChatRequest(GeminiModelId, bool)

Creates a new GeminiChatRequest.

public GeminiChatRequest(GeminiModelId model, bool useBetaApi = false)

Parameters

model GeminiModelId

The model to use.

useBetaApi bool

Should the request use the Beta API?

Fields

ApiVersion

The API version to use.

public string ApiVersion

Field Value

string

CachedContent

The name of the cached content used as context to serve the prediction. Format: cachedContents/{cachedContent}

public string CachedContent

Field Value

string

Remarks

Note: only used in explicit caching, where users can have control over caching (e.g. what content to cache) and enjoy guaranteed cost savings.

Only available in the beta API.

Contents

The content of the current conversation with the model.

public GeminiContent[] Contents

Field Value

GeminiContent[]

Remarks

For single-turn queries, this is a single instance. For multi-turn queries, this is a repeated field that contains conversation history + latest request.

GenerationConfig

Configuration options for model generation and outputs.

public GeminiGenerationConfiguration GenerationConfig

Field Value

GeminiGenerationConfiguration

Model

The model to use.

public GeminiModelId Model

Field Value

GeminiModelId

OnPartialResponseReceived

Callback for receiving streamed responses.

public Func<GeminiChatResponse, Task> OnPartialResponseReceived

Field Value

Func<GeminiChatResponse, Task>

SafetySettings

A list of unique GeminiSafetySettings instances for blocking unsafe content.

public GeminiSafetySettings[] SafetySettings

Field Value

GeminiSafetySettings[]

Remarks

This will be enforced on Contents and Candidates.
There should not be more than one setting for each GeminiSafetyHarmCategory type. The API will block any
contents and responses that fail to meet the thresholds set by these settings. This list overrides the default
settings for each GeminiSafetyHarmCategory specified in the SafetySettings. If there is
no GeminiSafetySettings for a given GeminiSafetyHarmCategory provided in the list, the API will use the
default safety setting for that category. Harm categories HateSpeech,
SexuallyExplicit, DangerousContent and
Harassment are supported.

SystemInstruction

Developer set system instruction. Currently, text only.

public GeminiContent SystemInstruction

Field Value

GeminiContent

Remarks

Only available in the beta API.

ToolConfig

Tool configuration for any Tool specified in the request.

public GeminiToolConfiguration ToolConfig

Field Value

GeminiToolConfiguration

Remarks

Only available in the beta API.

Tools

A list of Tools the model may use to generate the next response.

public GeminiTool[] Tools

Field Value

GeminiTool[]

Remarks

A Tool is a piece of code that enables the system to interact with external systems to perform an action, or set of actions,
outside of knowledge and scope of the model.The only supported tool is currently Function.

Only available in the beta API.

s_partialDataSerializerSettings

Serialization settings for deserializing partial streamed responses.

private static readonly JsonSerializerSettings s_partialDataSerializerSettings

Field Value

JsonSerializerSettings

Properties

AuthMethod

The preferred authentication method.

public GeminiAuthMethod AuthMethod { get; set; }

Property Value

GeminiAuthMethod

ContentType

The MIME type of the request content.

public string ContentType { get; }

Property Value

string

OAuthAccessToken

The OAuth access token to authenticate the request, if using OAuthAccessToken as AuthMethod.

public string OAuthAccessToken { get; set; }

Property Value

string

StreamedResponse

The streamed response.

public GeminiChatResponse StreamedResponse { get; private set; }

Property Value

GeminiChatResponse

Methods

GetEndpointUri(GeminiRequestMetadata)

Gets the URI to the API endpoint.

public string GetEndpointUri(GeminiRequestMetadata metadata)

Parameters

metadata GeminiRequestMetadata

The metadata of the request to be carried out on the URI.

Returns

string

The URI.

GetUtf8EncodedData()

Converts the request object to a UTF-8 encoded string.

public string GetUtf8EncodedData()

Returns

string

The string data.

ProcessStreamedData(List<JToken>, JToken)

Callback to process Server Sent Events (SSEs).

public Task ProcessStreamedData(List<JToken> allEvents, JToken lastEvent)

Parameters

allEvents List<JToken>

All previously sent SSEs.

lastEvent JToken

The latest SSE.

Returns

Task