Overview
Integration details
| Class | Package | Local | Serializable | JS support | Downloads | Version |
|---|---|---|---|---|---|---|
ChatGoogleGenerativeAI | langchain-google-genai | ❌ | beta | ✅ |
Model features
| Tool calling | Structured output | JSON mode | Image input | Audio input | Video input | Token-level streaming | Native async | Token usage | Logprobs |
|---|---|---|---|---|---|---|---|---|---|
| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
Setup
To access Google AI models you’ll need to create a Google Account, get a Google AI API key, and install thelangchain-google-genai integration package.
Installation
Credentials
Head to the Google AI Studio to generate a Google AI API key. Once you’ve done this set theGOOGLE_API_KEY environment variable in your environment:
Instantiation
Now we can instantiate our model object and generate responses:ChatGoogleGenerativeAI API Reference for the full set of available model parameters.
Invocation
Multimodal usage
Gemini models can accept multimodal inputs (text, images, audio, video) and, for some models, generate multimodal outputs.Image input
Provide image inputs along with text using aHumanMessage with a list content format.
Make sure to use a model that supports image input, such as gemini-2.5-flash.
image_url formats:
- A Google Cloud Storage URI (
gs://...). Ensure the service account has access. - A PIL Image object (the library handles encoding).
Audio input
Provide audio file inputs along with text.Video input
Provide video file inputs along with text.Image generation
Certain models (such asgemini-2.5-flash-image) can generate text and images inline.
See more information on the Gemini API docs for details.
Audio generation
Certain models (such asgemini-2.5-flash-preview-tts) can generate audio files.
See more information on the Gemini API docs for details.
Tool calling
You can equip the model with tools to call.Structured output
Force the model to respond with a specific structure. See the Gemini API docs for more info.+=:
Structured output methods
Two methods are supported for structured output:method="function_calling"(default): Uses tool calling to extract structured data.method="json_mode": Uses Gemini’s native structured output.
json_mode method is recommended for better reliability as it constrains the model’s generation process directly rather than relying on post-processing tool calls.
Token usage tracking
Access token usage information from the response metadata.Built-in tools
Google Gemini supports a variety of built-in tools (google search, code execution), which can be bound to the model in the usual way.Thinking Support
See the Gemini API docs for more info.Safety settings
Gemini models have default safety settings that can be overridden. If you are receiving lots of “Safety Warnings” from your models, you can try tweaking thesafety_settings attribute of the model. For example, to turn off safety blocking for dangerous content, you can construct your LLM as follows:
API reference
For detailed documentation of all features and configuration options, head to theChatGoogleGenerativeAI API reference.