Class GoogleGenAiStreamingChatModel.Builder
- Enclosing class:
GoogleGenAiStreamingChatModel
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionallowedFunctionNames(List<String> allowedFunctionNames) Restricts function calling to only the specified function names.apiEndpoint(String apiEndpoint) Overrides the default API endpoint.Sets the Google AI Gemini API key used to authenticate requests.build()cachedContent(String cachedContent) Sets the name of a previously created cached content resource to use with this model.client(com.google.genai.Client client) Sets a pre-configured Google GenAIClient.customHeaders(Map<String, String> customHeaders) Sets extra HTTP headers to include in every request to the Google GenAI API.defaultRequestParameters(ChatRequestParameters defaultRequestParameters) Sets defaultChatRequestParametersthat are merged into every request.enableGoogleMaps(boolean googleMaps) Enables the Google Maps grounding tool, allowing the model to retrieve location-based information.enableGoogleSearch(boolean googleSearch) Enables the Google Search grounding tool, allowing the model to retrieve real-time information from the web.enableUrlContext(boolean urlContext) Enables the URL context tool, allowing the model to read and reason about content at provided URLs.executor(ExecutorService executor) Executor used to drive the blockingResponseStreamiteration off the calling thread.frequencyPenalty(Double frequencyPenalty) Sets the frequency penalty, which reduces the likelihood of repeating tokens proportionally to how often they have appeared in the response so far.googleCredentials(com.google.auth.oauth2.GoogleCredentials credentials) Sets the Google OAuth2 credentials used to authenticate requests via Vertex AI.Sets labels (key-value metadata) attached to the request.listeners(List<ChatModelListener> listeners) Sets the list ofChatModelListeners to be notified on each request and response.Sets the Google Cloud region/location for Vertex AI access (e.g.logRequests(Boolean logRequests) Enables debug logging of request details sent to the Google GenAI API.logRequestsAndResponses(Boolean logRequestsAndResponses) Enables debug logging of both request and response details.logResponses(Boolean logResponses) Enables debug logging of response details received from the Google GenAI API.maxOutputTokens(Integer maxOutputTokens) Sets the maximum number of tokens to generate in the response.Sets the model to use for streaming chat completions.presencePenalty(Double presencePenalty) Sets the presence penalty, which reduces the likelihood of repeating any token that has already appeared in the response, regardless of frequency.Sets the Google Cloud project ID for Vertex AI access.responseFormat(ResponseFormat responseFormat) Sets the response format, enabling structured output such as JSON mode or JSON Schema.safetySettings(List<com.google.genai.types.SafetySetting> safetySettings) Sets safety content filter settings to block harmful content.Sets the random seed for deterministic output.stopSequences(List<String> stopSequences) Sets sequences that, when generated, will cause the model to stop generating further tokens.temperature(Double temperature) Sets the sampling temperature in the range[0.0, 2.0].thinkingBudget(Integer thinkingBudget) The thinking budget to use.thinkingLevel(String thinkingLevel) The thinking level to use.Sets the HTTP request timeout for calls to the Google GenAI API.Sets the top-K sampling value.Sets the nucleus sampling probability (top-p).vertexSearchDatastore(String vertexSearchDatastore) Sets the Vertex AI Search datastore to use for grounding the model's responses with enterprise data.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
client
Sets a pre-configured Google GenAIClient.Use this when you need full control over client configuration. When set,
apiKey(String),googleCredentials(GoogleCredentials),projectId(String),location(String), andtimeout(Duration)are ignored.- Parameters:
client- the pre-configured client- Returns:
this
-
googleCredentials
public GoogleGenAiStreamingChatModel.Builder googleCredentials(com.google.auth.oauth2.GoogleCredentials credentials) Sets the Google OAuth2 credentials used to authenticate requests via Vertex AI.Use this instead of
apiKey(String)when authenticating with a service account or Application Default Credentials (ADC). RequiresprojectId(String)andlocation(String)to be set.- Parameters:
credentials- the Google OAuth2 credentials- Returns:
this
-
apiKey
Sets the Google AI Gemini API key used to authenticate requests.Use this for the Google AI Studio API. For Vertex AI, use
googleCredentials(GoogleCredentials). Alternatively, set theGOOGLE_API_KEYenvironment variable.- Parameters:
apiKey- the API key- Returns:
this
-
projectId
Sets the Google Cloud project ID for Vertex AI access.Required when using
googleCredentials(GoogleCredentials)for Vertex AI.- Parameters:
projectId- the GCP project ID- Returns:
this
-
location
Sets the Google Cloud region/location for Vertex AI access (e.g."us-central1").Required when using
googleCredentials(GoogleCredentials)for Vertex AI.- Parameters:
location- the GCP region- Returns:
this
-
modelName
Sets the model to use for streaming chat completions.Examples:
"gemini-2.0-flash","gemini-2.5-pro".- Parameters:
modelName- the model name- Returns:
this
-
timeout
Sets the HTTP request timeout for calls to the Google GenAI API.- Parameters:
timeout- the request timeout- Returns:
this
-
temperature
Sets the sampling temperature in the range[0.0, 2.0]. Higher values produce more creative output; lower values produce more deterministic output.- Parameters:
temperature- the sampling temperature- Returns:
this
-
topP
Sets the nucleus sampling probability (top-p). Only the tokens whose cumulative probability exceeds this threshold are considered.- Parameters:
topP- the nucleus sampling threshold- Returns:
this
-
topK
Sets the top-K sampling value. Only thetopKmost-likely next tokens are considered at each step.- Parameters:
topK- the number of top tokens to sample from- Returns:
this
-
frequencyPenalty
Sets the frequency penalty, which reduces the likelihood of repeating tokens proportionally to how often they have appeared in the response so far.- Parameters:
frequencyPenalty- the frequency penalty- Returns:
this
-
presencePenalty
Sets the presence penalty, which reduces the likelihood of repeating any token that has already appeared in the response, regardless of frequency.- Parameters:
presencePenalty- the presence penalty- Returns:
this
-
maxOutputTokens
Sets the maximum number of tokens to generate in the response.- Parameters:
maxOutputTokens- the maximum number of output tokens- Returns:
this
-
thinkingBudget
The thinking budget to use. This is a legacy parameter. For Gemini 3.x models, usethinkingLevel(String)instead. -
thinkingLevel
The thinking level to use. This is the recommended parameter for Gemini 3.x models. Allowed values are"MINIMAL","LOW","MEDIUM","HIGH". Note that this cannot be used together withthinkingBudget(Integer). -
seed
Sets the random seed for deterministic output. Requests with the same seed and parameters should produce the same response.- Parameters:
seed- the random seed- Returns:
this
-
stopSequences
Sets sequences that, when generated, will cause the model to stop generating further tokens.- Parameters:
stopSequences- the list of stop sequences- Returns:
this
-
safetySettings
public GoogleGenAiStreamingChatModel.Builder safetySettings(List<com.google.genai.types.SafetySetting> safetySettings) Sets safety content filter settings to block harmful content. See the safety settings docs.- Parameters:
safetySettings- the list of safety settings- Returns:
this
-
responseFormat
Sets the response format, enabling structured output such as JSON mode or JSON Schema.- Parameters:
responseFormat- the desired response format- Returns:
this
-
enableGoogleSearch
Enables the Google Search grounding tool, allowing the model to retrieve real-time information from the web. See the Google Search tool docs.- Parameters:
googleSearch- whether to enable Google Search- Returns:
this
-
enableGoogleMaps
Enables the Google Maps grounding tool, allowing the model to retrieve location-based information. See the Google Maps tool docs.- Parameters:
googleMaps- whether to enable Google Maps- Returns:
this
-
enableUrlContext
Enables the URL context tool, allowing the model to read and reason about content at provided URLs. See the URL context tool docs.- Parameters:
urlContext- whether to enable URL context- Returns:
this
-
allowedFunctionNames
public GoogleGenAiStreamingChatModel.Builder allowedFunctionNames(List<String> allowedFunctionNames) Restricts function calling to only the specified function names. When set, the model can only call functions whose names appear in this list.- Parameters:
allowedFunctionNames- the list of allowed function names- Returns:
this
-
listeners
Sets the list ofChatModelListeners to be notified on each request and response. Useful for logging, metrics, and observability integrations.- Parameters:
listeners- the chat model listeners- Returns:
this
-
executor
Executor used to drive the blockingResponseStreamiteration off the calling thread. If not set, a shared default executor fromDefaultExecutorProvideris used.Strongly recommended: supply an executor managed by your application (Spring/Quarkus task executor, virtual-thread executor, bounded pool, etc.). The default executor is unbounded and not tied to any application lifecycle, so it offers no back-pressure or graceful shutdown.
-
defaultRequestParameters
public GoogleGenAiStreamingChatModel.Builder defaultRequestParameters(ChatRequestParameters defaultRequestParameters) Sets defaultChatRequestParametersthat are merged into every request. Individual request parameters take precedence over these defaults.- Parameters:
defaultRequestParameters- the default request parameters- Returns:
this
-
cachedContent
Sets the name of a previously created cached content resource to use with this model. Using cached content can reduce latency and cost for repeated prompts. See the context caching docs.- Parameters:
cachedContent- the cached content resource name- Returns:
this
-
vertexSearchDatastore
Sets the Vertex AI Search datastore to use for grounding the model's responses with enterprise data.- Parameters:
vertexSearchDatastore- the Vertex AI Search datastore resource name- Returns:
this
-
labels
Sets labels (key-value metadata) attached to the request. Useful for cost attribution and billing tracking in Google Cloud.- Parameters:
labels- a map of label keys to values- Returns:
this
-
apiEndpoint
Overrides the default API endpoint.Useful for pointing at a regional endpoint or a compatible proxy.
- Parameters:
apiEndpoint- the custom API endpoint URL- Returns:
this
-
customHeaders
Sets extra HTTP headers to include in every request to the Google GenAI API.- Parameters:
customHeaders- a map of header names to values- Returns:
this
-
logRequests
Enables debug logging of request details sent to the Google GenAI API.- Parameters:
logRequests- whether to log requests- Returns:
this
-
logResponses
Enables debug logging of response details received from the Google GenAI API.- Parameters:
logResponses- whether to log responses- Returns:
this
-
logRequestsAndResponses
public GoogleGenAiStreamingChatModel.Builder logRequestsAndResponses(Boolean logRequestsAndResponses) Enables debug logging of both request and response details. Equivalent to calling bothlogRequests(Boolean)andlogResponses(Boolean).- Parameters:
logRequestsAndResponses- whether to log requests and responses- Returns:
this
-
build
-