ChatGoogle chat models.
For detailed documentation of all ChatGoogle features and configurations head to the
API reference.
Overview
Integration details
Model features
See the links in the table headers below for guides on how to use specific features.
Note that while logprobs are supported, Gemini has fairly restricted usage of them.
Setup
Credentials through AI Studio (API Key)
To use the model through Google AI Studio (sometimes called the Generative AI API), you will need an API key. You can obtain one from the Google AI Studio. Once you have your API key, you can set it as an environment variable:Credentials through Vertex AI Express Mode (API Key)
Vertex AI also supports Express Mode, which allows you to use an API key for authentication. You can obtain a Vertex AI API key from the Google Cloud Console. Once you have your API key, you can set it as an environment variable:gcp when instantiating the model.
Credentials through Vertex AI (OAuth Application Default Credentials / ADC)
For production environments on Google Cloud, it is recommended to use Application Default Credentials (ADC). This is supported in Node.js environments. If you are running on a local machine, you can set up ADC by installing the Google Cloud SDK and running:GOOGLE_APPLICATION_CREDENTIALS environment
variable to the path of your service account key file:
Credentials through Vertex AI (OAuth saved credentials)
If you are running in a web environment or want to provide credentials directly, you can use theGOOGLE_CLOUD_CREDENTIALS environment variable. This should
contain the content of your service account key file (not the path).
credentials parameter.
Tracing
If you want to get automated tracing of your model calls you can also set your LangSmith API key by uncommenting below:Installation
The LangChainChatGoogle integration lives in the @langchain/google package:
Instantiation
The import path differs depending on whether you are running in a Node.js environment or a Web/Edge environment.- If you provide an
apiKey(or setGOOGLE_API_KEY), it defaults to Google AI. - If you provide
credentials(or setGOOGLE_APPLICATION_CREDENTIALS/GOOGLE_CLOUD_CREDENTIALSin Node), it defaults to Vertex AI.
Google AI (AI Studio)
Vertex AI
Vertex AI Express Mode
To use Vertex AI with an API key (Express Mode), you must explicitly set theplatformType.
Model Configuration Best Practices
WhileChatGoogle supports standard model parameters like temperature, topP, and topK,
best practice with Gemini models is to leave these at their default values. The models
are highly tuned around these defaults.
If you want to control the “randomness” or “creativity” of the model, it is recommended
to use specific instructions in your prompt or system prompt (e.g., “Be creative”,
“Give a concise factual answer”) rather than adjusting the temperature.
Invocation
Response Metadata
TheAIMessage response contains metadata about the generation, including
token usage and log probabilities.
Token Usage
Theusage_metadata property allows you to inspect token counts.
Logprobs
If you enablelogprobs in the model configuration, they will be available in
the response_metadata.
Safety settings
By default, current versions of Gemini have safety settings turned off. If you want to enable safety settings for various categories, you can use thesafetySettings attribute of the model.
Structured output
You can use thewithStructuredOutput method to get structured JSON output from the model.
Tool calling
ChatGoogle supports standard LangChain tool calling as
well as Gemini-specific “Specialty Tools” (like Code Execution and Grounding).
Standard Tools
You can use standard LangChain tools defined with Zod schemas.Specialty Tools
Gemini offers several built-in tools for code execution and grounding.Code execution
Gemini models support code execution, which allows the model to generate and run Python code to solve complex problems.Grounding with Google Search
You can use thegoogleSearch tool to ground responses with Google Search.
This is useful for questions about current events or specific facts.
The
googleSearchRetrieval tool is maintained for backwards compatibility, but googleSearch is preferred.Grounding with URL Retrieval
You can also ground responses using a specific URL.Grounding with a data store
If you are using Vertex AI (platformType: "gcp"), you can ground responses using
a Vertex AI Search data store.
Context caching
By default, Gemini models do implicit context caching. If the start of the history that you send to Gemini exactly matches context that Gemini has in its cache, it will reduce the token cost for that request. You can also explicitly pass some content to the model once, cache the input tokens, and then refer to the cached tokens for subsequent requests to reduce cost and latency. Creating this explicit cache is not supported by LangChain, but if you have created the cache, you can reference it in your invocation.Multimodal Requests
TheChatGoogle model supports multimodal requests, allowing you to send images,
audio, and video along with text. You can use the contentBlocks field in your
messages to provide these inputs in a structured way.
Images
Audio
Video
Reasoning / Thinking
Google’s Gemini 2.5 and Gemini 3 models support “thinking” or “reasoning” steps. These models may perform reasoning even if you don’t explicitly configure it, but the library will only return the reasoning summaries (thought blocks) if you explicitly set a value for how much to reason/think. This library offers compatibility between models, allowing you to use unified parameters:-
maxReasoningTokens(orthinkingBudget): Specifies the maximum number of tokens to use for reasoning.0: Turns off reasoning (if supported).-1: Uses the model’s default.> 0: Sets the specific token budget.
-
reasoningEffort(orthinkingLevel): Sets the relative effort.- Values:
"minimal","low","medium","high".
- Values:
Thought blocks also include a
reasoningContentBlock field. This contains the ContentBlock based on
the underlying part sent by Gemini. While this is typically a text block, for multimodal models like
Nano Banana Pro, it could be an image or other media block.Image Generation with Nano Banana and Nano Banana Pro
To generate images, you need to use a model that supports it (such asgemini-2.5-flash-image) and configure the responseModalities to
include “IMAGE”.
Speech Generation (TTS)
Some Gemini models support generating speech (audio output). To enable this, configure theresponseModalities to include “AUDIO” and provide a
speechConfig.
The speechConfig can be a
full Gemini speech configuration object,
but for most cases you just need to provide a string with a prebuilt
voice name.
Many models return audio in raw PCM format (audio/L16), which requires a
WAV header to be playable by most media players.
Multi-speaker TTS
You can also configure multiple speakers for a single request. This is useful to have Gemini read a script. The simplifiedspeechConfig for this requires you to assign
a speaker to each pre-defined name representing the voice, and then use that
speaker in the script.
API Reference
For detailed documentation of allChatGoogle features and configurations head to the
API reference.
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

