GeminiVisionClient

org.llm4s.imageprocessing.provider.geminiclient.GeminiVisionClient

Google Gemini Vision client for AI-powered image analysis.

Sends multimodal requests (image + text prompt) to the Gemini generateContent REST endpoint and returns structured analysis results.

The API key is sent in the x-goog-api-key request header, never in the URL, so it cannot reach a log line or an error message through the URL.

Failures are returned, not thrown: an HTTP error status is an org.llm4s.error.APIError carrying the status code; a timeout, connection failure or interruption is the typed org.llm4s.error.TimeoutError, org.llm4s.error.NetworkError or org.llm4s.error.CancelledError; a reply that carries no text (a blocked prompt, a candidate stopped for safety or recitation, a body that is not Gemini JSON) is an org.llm4s.error.APIError too, never a made-up description.

Value parameters

config

GeminiVisionConfig containing the API key, model, and base URL.

httpClient

the HTTP transport; defaults to the JDK client honouring config.connectTimeoutSeconds.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Constructors

def this(config: GeminiVisionConfig)

Concrete methods

override def analyzeImage(imagePath: String, prompt: Option[String]): Either[LLMError, ImageAnalysisResult]

Analyses an image using the Google Gemini Vision API.

Analyses an image using the Google Gemini Vision API.

Value parameters

imagePath

Path to the image file to analyse.

prompt

Optional custom prompt; a default comprehensive prompt is used when absent.

Attributes

Returns

Either an LLMError on failure or an ImageAnalysisResult.

Definition Classes
override def convertFormat(imagePath: String, targetFormat: ImageMediaType): Either[LLMError, ProcessedImage]

Converts image format.

Converts image format.

Value parameters

imagePath

Path to the input image

targetFormat

Target image format

Attributes

Returns

Either error or converted image

Definition Classes
def detectMediaType(imagePath: String): ImageMediaType

Detects the MIME media type of the image from its file extension.

Detects the MIME media type of the image from its file extension.

Value parameters

imagePath

Path to the image file.

Attributes

Returns

MediaType inferred from the file extension (defaults to JPEG).

def encodeImageToBase64(imagePath: String): Try[String]

Encodes the image at imagePath to a Base64 string.

Encodes the image at imagePath to a Base64 string.

Value parameters

imagePath

Absolute or relative path to the image file.

Attributes

Returns

scala.util.Try wrapping the Base64 string on success.

override def preprocessImage(imagePath: String, operations: List[ImageOperation]): Either[LLMError, ProcessedImage]

Preprocesses an image with specified operations.

Preprocesses an image with specified operations.

Value parameters

imagePath

Path to the input image

operations

List of preprocessing operations to apply

Attributes

Returns

Either error or processed image

Definition Classes
override def resizeImage(imagePath: String, width: Int, height: Int, maintainAspectRatio: Boolean): Either[LLMError, ProcessedImage]

Resizes an image to specified dimensions.

Resizes an image to specified dimensions.

Value parameters

height

Target height

imagePath

Path to the input image

maintainAspectRatio

Whether to maintain aspect ratio

width

Target width

Attributes

Returns

Either error or resized image

Definition Classes

Inherited methods

def analyzeImageAsync(imagePath: String, prompt: Option[String])(implicit ec: ExecutionContext): Future[Either[LLMError, ImageAnalysisResult]]

Asynchronously analyzes an image and returns a description.

Asynchronously analyzes an image and returns a description.

Default implementation wraps the synchronous call in a Future with an explicit blocking boundary to avoid starving compute pools.

Value parameters

ec

ExecutionContext for async execution

imagePath

Path to the image file

prompt

Optional prompt to guide the analysis

Attributes

Returns

Future containing either error or image analysis result

Inherited from:
ImageProcessingClient