Skip to main content

Overview

ChatGoogle provides integration with Google’s Gemini models including Gemini 2.0 Flash, Gemini 2.5 Pro, and Gemini 3 series with advanced thinking capabilities.

Basic Usage

Configuration

Required Parameters

str
required
Gemini model to use. Available options:Latest Models:
  • gemini-flash-latest: Latest Flash model (recommended)
  • gemini-flash-lite-latest: Lightweight Flash model
Gemini 3 Series:
  • gemini-3-pro-preview: Most powerful with advanced reasoning
  • gemini-3-flash-preview: Fast with thinking capabilities
Gemini 2.5 Series:
  • gemini-2.5-pro: High-performance Pro model
  • gemini-2.5-flash: Fast and efficient
  • gemini-2.5-flash-lite: Lightweight option
Gemini 2.0 Series:
  • gemini-2.0-flash: Standard Flash
  • gemini-2.0-flash-exp: Experimental Flash
  • gemini-2.0-flash-lite-preview-02-05: Lite preview
Gemma Models:
  • gemma-3-27b-it, gemma-3-4b, gemma-3-12b: Open models
  • gemma-3n-e2b, gemma-3n-e4b: Nano models

Model Parameters

float
default:"0.5"
Sampling temperature (0.0 to 2.0). Controls randomness in responses.
float
default:"None"
Nucleus sampling parameter (0.0 to 1.0).
int
default:"None"
Random seed for deterministic output.
int
default:"8096"
Maximum tokens in the response.

Thinking Configuration

int
default:"None"
For Gemini 2.5 models: Control thinking tokens.
  • -1: Dynamic/auto (default)
  • 0: Disable thinking
  • > 0: Specific token count for thinking
str
default:"None"
For Gemini 3 models: Control reasoning depth.
  • Gemini 3 Pro: low, high
  • Gemini 3 Flash: minimal, low, medium, high

Client Parameters

str
default:"None"
Google API key. Defaults to GOOGLE_API_KEY environment variable.
Get your free API key at aistudio.google.com/app/apikey
bool
default:"None"
Whether to use Vertex AI instead of AI Studio.
Credentials
default:"None"
Google Cloud credentials object for Vertex AI.
str
default:"None"
Google Cloud project ID for Vertex AI.
str
default:"None"
Google Cloud region for Vertex AI (e.g., us-central1).

Advanced Parameters

bool
default:"False"
Include system messages in the first user message (for models without system instruction support).
bool
default:"True"
Use native JSON mode. Set to False for prompt-based fallback.
int
default:"5"
Number of retries for retryable errors.
list[int]
default:"[429, 500, 502, 503, 504]"
HTTP status codes to retry on.
float
default:"1.0"
Base delay in seconds for exponential backoff.
float
default:"60.0"
Maximum delay between retries.

Advanced Usage

Gemini 3 with Thinking

Gemini 2.5 with Dynamic Thinking

Structured Output

Using Vertex AI

With Code Execution Tool

Environment Setup

.env

Error Handling

Properties

provider

Returns the provider name: "google"

name

Returns the model name.

Methods

get_client()

Returns a genai.Client instance.

ainvoke()

Asynchronously invoke the model with messages.

Parameters

  • messages (list[BaseMessage]): List of messages
  • output_format (type[T] | None): Optional Pydantic model for structured output

Returns

ChatInvokeCompletion[T] | ChatInvokeCompletion[str] with:
  • completion: Response content
  • usage: Token usage including:
    • prompt_tokens: Input tokens
    • completion_tokens: Output tokens (includes thinking tokens for Gemini 2.5/3)
    • prompt_cached_tokens: Cached tokens
    • prompt_image_tokens: Tokens from images
  • stop_reason: Completion reason

Token Usage

Gemini includes thinking tokens in completion counts:

Thinking Models

Gemini 3 Pro

  • Uses thinking_level: low or high
  • Best for complex reasoning
  • Validates unsupported thinking configurations

Gemini 3 Flash

  • Supports all thinking_level values: minimal, low, medium, high
  • Defaults to thinking_budget=-1 if no thinking_level set
  • Balances speed and reasoning

Gemini 2.5

  • Uses thinking_budget only
  • -1 for dynamic thinking (default)
  • 0 to disable
  • Set specific token count for controlled thinking

Model Comparison