Class GoogleAiGeminiImageModel.GoogleAiGeminiImageModelBuilder
java.lang.Object
dev.langchain4j.model.googleai.GoogleAiGeminiImageModel.GoogleAiGeminiImageModelBuilder
- Enclosing class:
GoogleAiGeminiImageModel
Builder for constructing
GoogleAiGeminiImageModel instances.-
Method Summary
Modifier and TypeMethodDescriptionSets the API key for authenticating with the Gemini API.aspectRatio(String aspectRatio) Sets the aspect ratio for generated images.Sets a custom base URL for the Gemini API.build()Builds a newGoogleAiGeminiImageModelinstance.httpClientBuilder(HttpClientBuilder httpClientBuilder) Sets the HTTP client builder for custom HTTP configuration.Sets the image size/resolution for generated images.logger(org.slf4j.Logger logger) Sets a custom logger for request/response logging.logRequests(Boolean logRequests) Enables or disables logging of requests only.logRequestsAndResponses(Boolean logRequestsAndResponses) Enables or disables logging of both requests and responses.logResponses(Boolean logResponses) Enables or disables logging of responses only.maxRetries(Integer maxRetries) Sets the maximum number of retries for failed requests.Sets the model name to use for image generation.safetySettings(List<GeminiSafetySetting> safetySettings) Sets safety settings to control content filtering.Sets the timeout for API requests.
-
Method Details
-
httpClientBuilder
public GoogleAiGeminiImageModel.GoogleAiGeminiImageModelBuilder httpClientBuilder(HttpClientBuilder httpClientBuilder) Sets the HTTP client builder for custom HTTP configuration.- Parameters:
httpClientBuilder- the HTTP client builder- Returns:
- this builder
-
apiKey
Sets the API key for authenticating with the Gemini API.- Parameters:
apiKey- the Google AI API key (required)- Returns:
- this builder
-
baseUrl
Sets a custom base URL for the Gemini API.- Parameters:
baseUrl- the base URL (optional, defaults to Google's API endpoint)- Returns:
- this builder
-
modelName
Sets the model name to use for image generation.Supported models:
gemini-2.5-flash-preview-image-generation(default) - Fast, efficient generationgemini-3-pro-image-preview- Advanced capabilities, up to 4K resolution
- Parameters:
modelName- the model name- Returns:
- this builder
-
aspectRatio
Sets the aspect ratio for generated images.Supported aspect ratios: "1:1", "2:3", "3:2", "3:4", "4:3", "4:5", "5:4", "9:16", "16:9", "21:9"
If not specified, the model defaults to matching the input image size or generating 1:1 squares.
- Parameters:
aspectRatio- the aspect ratio (e.g., "16:9")- Returns:
- this builder
-
imageSize
Sets the image size/resolution for generated images.Supported sizes (for gemini-3-pro-image-preview only): "1K", "2K", "4K"
Note: You must use an uppercase 'K'. Lowercase parameters will be rejected.
- Parameters:
imageSize- the image size (e.g., "2K")- Returns:
- this builder
-
timeout
Sets the timeout for API requests.- Parameters:
timeout- the timeout duration- Returns:
- this builder
-
maxRetries
Sets the maximum number of retries for failed requests.- Parameters:
maxRetries- the maximum number of retries (default: 2)- Returns:
- this builder
-
logRequestsAndResponses
public GoogleAiGeminiImageModel.GoogleAiGeminiImageModelBuilder logRequestsAndResponses(Boolean logRequestsAndResponses) Enables or disables logging of both requests and responses.- Parameters:
logRequestsAndResponses- true to enable logging- Returns:
- this builder
-
logRequests
Enables or disables logging of requests only.- Parameters:
logRequests- true to enable request logging- Returns:
- this builder
-
logResponses
Enables or disables logging of responses only.- Parameters:
logResponses- true to enable response logging- Returns:
- this builder
-
logger
Sets a custom logger for request/response logging.- Parameters:
logger- the SLF4J logger to use- Returns:
- this builder
-
safetySettings
public GoogleAiGeminiImageModel.GoogleAiGeminiImageModelBuilder safetySettings(List<GeminiSafetySetting> safetySettings) Sets safety settings to control content filtering.- Parameters:
safetySettings- the list of safety settings- Returns:
- this builder
-
build
Builds a newGoogleAiGeminiImageModelinstance.- Returns:
- the configured image model
- Throws:
IllegalArgumentException- if required parameters are missing
-