Usage guide
Setup, environment variables, and Python/JavaScript/Go usage examples.
GoogleLLM
Google Gemini LLM via the Gemini API or Vertex AI. Supports the full Gemini model family (2.5 and 3.x series) including thinking/reasoning models, safety-settings control, and optional service-account-authenticated Vertex AI routing.Constructor
Google AI Studio API key. Falls back to
GOOGLE_API_KEY env var. Ignored when vertexai=True.Gemini model ID. Known values (
GoogleLLMModel): "gemini-2.5-flash-lite" (default), "gemini-2.5-flash", "gemini-2.5-pro", "gemini-3-flash-preview", "gemini-3.1-pro-preview", "gemini-3.5-flash", "gemini-3.1-flash-lite", "gemini-flash-latest". Any string is accepted for forward compatibility.Sampling temperature controlling response randomness. Higher values produce more varied output. Default:
0.7.Maximum number of tokens in the generated response. Default:
8192.Token budget reserved for the model’s internal reasoning chain (applicable to thinking-capable models).
0 disables thinking; higher values allow deeper reasoning at the cost of latency and tokens. Default: 0.When
True and thinking_budget > 0, the model’s reasoning trace is included in the response alongside the final answer. Default: False.List of
{"category": ..., "threshold": ...} dicts overriding Gemini’s default harm-blocking thresholds. See Google AI safety-settings docs for valid category and threshold strings.Nucleus sampling probability mass cutoff (0.0–1.0).
None uses the model default.Top-K sampling limit.
None uses the model default.Penalises tokens that have already appeared, encouraging topic diversity (range typically −2.0–2.0).
None uses the model default.Penalises tokens proportional to how often they have appeared, reducing repetition (range typically −2.0–2.0).
None uses the model default.Fixed random seed for deterministic outputs when supported.
None uses non-deterministic sampling.When
True, routes requests through Vertex AI instead of the Gemini API. Requires project_id. Default: False.Google Cloud project ID. Required when
vertexai=True. Falls back to GOOGLE_CLOUD_PROJECT env var (resolved in the calling code).Vertex AI regional endpoint, e.g.
"us-central1" (default) or "europe-west4". Ignored when vertexai=False.Service-account credentials as a JSON string or dict. Used for Vertex AI authentication when
vertexai=True. Takes precedence over service_account_path.Path to a service-account JSON key file. Used when
service_account_json is not provided and vertexai=True. Falls back to GOOGLE_APPLICATION_CREDENTIALS env var.aclose
cancel_current_generation
chat
The conversation history to send to the model.
Optional tool definitions the model may call.
Optional conversational graph guiding the exchange.
LLMResponse: Response chunks produced as the model generates output.
emit
The event to emit.
off
The event the handler was registered for.
The handler to remove.
on
callback is omitted.
The event to listen for.
The handler to invoke when the event is emitted. If
None, a decorator is returned that registers the decorated function.The registered callback when
callback is provided, otherwise a decorator that registers and returns the function it wraps.