Skip to main content
Access Google’s Generative AI models, including the Gemini family, directly via the Gemini API or experiment rapidly using Google AI Studio. This is often the best starting point for individual developers. For information on the latest models, model IDs, their features, context windows, etc. head to the Google AI docs.
API ReferenceFor detailed documentation of all features and configuration options, head to the ChatGoogleGenerativeAI API reference.

Overview

Integration details

Model features

Setup

To access Google AI models you’ll need to create a Google Account, get a Google AI API key, and install the langchain-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 the GOOGLE_API_KEY environment variable in your environment:
To enable automated tracing of your model calls, set your LangSmith API key:

Instantiation

Now we can instantiate our model object and generate responses:
See the ChatGoogleGenerativeAI API Reference for the full set of available model parameters.

Invocation

Message content shapeGemini 3 series models will always return a list of content blocks to capture thought signatures. Use the .text property to recover string content.

Multimodal usage

Gemini models can accept multimodal inputs (text, images, audio, video) and, for some models, generate multimodal outputs.

Supported input methods

Image input

Provide image inputs along with text using a HumanMessage with a list content format.
Other supported image formats:
  • A Google Cloud Storage URI (gs://...). Ensure the service account has access.

PDF input

Provide PDF file inputs along with text.

Audio input

Provide audio file inputs along with text.

Video input

Provide video file inputs along with text.
YouTube limitations
  • Only public videos are supported (not private or unlisted)
  • Free tier: max 8 hours of YouTube video per day
  • Feature is currently in preview

File upload

You can upload files to Google’s servers and reference them by URI. This works for PDFs, images, videos, and audio files.

Image generation

Certain models (such as gemini-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 as gemini-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.
For streaming structured output, merge dictionaries instead of using +=:

Structured output methods

Two methods are supported for structured output:
  • method="function_calling" (default): Uses tool calling to extract structured data.
  • method="json_schema": Uses Gemini’s native structured output.
The json_schema 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.

Thinking support

With reasoning models, you have the option to adjust the number of internal thinking tokens used (thinking_budget) or to disable thinking altogether.
Not all models allow disabling thinking. See the Gemini models documentation for details.
To see a thinking model’s thoughts, set include_thoughts=True to have the model’s reasoning summaries included in the response.
See the Gemini API docs for more information on thinking.

Thought signatures

Thought signatures are encrypted representations of the model’s reasoning processes. They enable Gemini to maintain thought context across multi-turn conversations, since the API is stateless and treats each request independently.
Gemini 3 may raise 4xx errors if thought signatures are not passed back with tool call responses. Upgrade to langchain-google-genai >= 3.1.0 to ensure this is handled correctly.
Signatures appear in two places in AIMessage responses:
  • Text blocks: Stored in extras.signature within the content block
  • Tool calls: Stored in additional_kwargs["__gemini_function_call_thought_signatures__"]
For multi-turn conversations with tool calls, you must pass the full AIMessage back to the model so signatures are preserved. This happens automatically when you append the AIMessage to your messages list:
Don’t reconstruct messages manually. If you create a new AIMessage instead of passing the original object, the signatures will be lost and the API may reject the request.

Built-in tools

Google Gemini supports a variety of built-in tools, which can be bound to the model in the usual way. See Gemini docs for detail.

Code execution

See Gemini docs for detail.

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 the safety_settings attribute of the model. For example, to turn off safety blocking for dangerous content, you can construct your LLM as follows:
For an enumeration of the categories and thresholds available, see Google’s safety setting types.

Context caching

Context caching allows you to store and reuse content (e.g., PDFs, images) for faster processing. The cached_content parameter accepts a cache name created via the Google Generative AI API.
This caches a single file and queries it.
This caches two files using Part and queries them together.
See the Gemini API docs on context caching for more information.

Response metadata

Access response metadata from the model response.

API reference

For detailed documentation of all features and configuration options, head to the ChatGoogleGenerativeAI API reference.
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.