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 | None = None, timeout: float = 60.0)[source]#
Bases:
BaseAPIInferenceModelGoogle Gemini
generateContentclient for image + text prompts.The key is read from
api_key(string or key-file path) or theGOOGLE_API_KEYenvironment variable. Safety filters are set toBLOCK_NONEbecause 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 Gemini models that support
generateContent.list_known_modelsReturn the curated catalog of model IDs for this provider.
run_batchRun
run_inference()over many assets with a thread pool.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 catalog is returned instead.
- Parameters:
api_key – Key string, key-file path, or
Nonefor 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/jsonoutput.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
Nonewhen the request failed, was blocked by safety filters, or nothing could be sent. When the output limit is used up before any answer is written (thinking counts against it on Gemini 4), the output is a failure whoseerrorsays to raisemax_tokens; an answer cut off partway is returned with a logged warning.
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.'