GeminiInference#

class rapidtools.models.GeminiInference(api_key: str | Path | None = None, model_id: str = 'gemini-3.8-flash', max_workers: int = 10, max_retries: int = 3, system_instruction: str | None = None, temperature: float = 0.4, max_tokens: int = 2048, timeout: float = 60.0)[source]#

Bases: BaseAPIInferenceModel

Google Gemini generateContent client for image + text prompts.

The key is read from api_key (string or key-file path) or the GOOGLE_API_KEY environment variable. Safety filters are set to BLOCK_NONE because damage imagery is frequently mis-flagged.

Example

>>> from rapidtools.models import GeminiInference
>>> GeminiInference.list_known_models()[0]
'gemini-3.8-flash'
>>> model = GeminiInference(api_key='AIza...')
>>> out = model.run_inference(
...     'house.jpg', 'Return JSON with a chs_level key (0-5).', json_mode=True
... )
>>> out.text
'{"chs_level": 3}'

Methods

list_available_models

List Gemini models that support generateContent.

list_known_models

Return the curated catalogue of model IDs for this provider.

run_batch

Run run_inference() over many assets with a thread pool.

run_inference

Send images and a prompt to generateContent.

classmethod list_available_models(api_key: str | Path | None = None) → list[str][source]#

List Gemini models that support generateContent.

Without a key (or when the API cannot be reached) the curated catalogue is returned instead.

Parameters:

api_key – Key string, key-file path, or None for the env var.

Returns:

list[str] – Sorted model IDs without the models/ prefix.

Example

>>> from rapidtools.models import GeminiInference
>>> ids = GeminiInference.list_available_models('AIza...')
>>> 'gemini-3.8-flash' in ids
True
run_inference(image_inputs: str | Path | list[str | Path], prompt: str | Path, json_mode: bool = False, max_retries: int | None = None, temperature: float | None = None, max_tokens: int | None = None, config: GenerationConfig | None = None, **kwargs: Any) → ModelOutput | None[source]#

Send images and a prompt to generateContent.

Parameters:
  • image_inputs – One path/URL or a list of them. Unreadable images are skipped with a logged error; text-only prompts are allowed by passing [].

  • prompt – Prompt text or path to a prompt file.

  • json_mode – Request application/json output.

  • max_retries – Per-call override of the session retry count.

  • temperature – Per-call temperature override.

  • max_tokens – Per-call output-token limit override.

  • config – A GenerationConfig; explicit keyword arguments take precedence over it.

  • **kwargs – Ignored; accepted for interface compatibility.

Returns:

ModelOutput | None – The response text and raw JSON, or None when the request failed, was blocked by safety filters, or nothing could be sent.

Example

>>> from rapidtools.models import GeminiInference
>>> model = GeminiInference(api_key='AIza...')
>>> model.run_inference(['a.jpg', 'b.jpg'], 'Which roof is worse?').text
'The roof in the second image shows more severe damage.'