{"id":1529,"library":"langchain-google-genai","title":"LangChain Google Generative AI","description":"LangChain Google Generative AI provides integrations with Google's GenAI models (like Gemini) for use within the LangChain framework. It offers classes for chat models, traditional LLMs, and embeddings. The current version is 4.2.1, and it's actively maintained with frequent updates within the larger LangChain Google monorepo.","status":"active","version":"4.2.1","language":"en","source_language":"en","source_url":"https://github.com/langchain-ai/langchain-google/tree/master/libs/genai","tags":["Google","Generative AI","Gemini","LLM","Embeddings","LangChain","AI","Google Cloud"],"install":[{"cmd":"pip install langchain-google-genai","lang":"bash","label":"Install package"}],"dependencies":[{"reason":"Core client library for interacting with Google's Generative AI services.","package":"google-generativeai","optional":false},{"reason":"Provides the foundational interfaces and classes for LangChain integrations.","package":"langchain-core","optional":false}],"imports":[{"note":"The `ChatGooglePalm` class from the main `langchain` package is deprecated. Use `ChatGoogleGenerativeAI` from `langchain-google-genai` for current Gemini models.","wrong":"from langchain.chat_models import ChatGooglePalm","symbol":"ChatGoogleGenerativeAI","correct":"from langchain_google_genai import ChatGoogleGenerativeAI"},{"note":"The `GooglePalm` class from the main `langchain` package is deprecated. Use `GoogleGenerativeAI` from `langchain-google-genai` for current Gemini models.","wrong":"from langchain.llms import GooglePalm","symbol":"GoogleGenerativeAI","correct":"from langchain_google_genai import GoogleGenerativeAI"},{"note":"Provides embedding functionality for Google's generative models.","symbol":"GoogleGenerativeAIEmbeddings","correct":"from langchain_google_genai import GoogleGenerativeAIEmbeddings"}],"quickstart":{"code":"import os\nfrom langchain_google_genai import ChatGoogleGenerativeAI\nfrom langchain_core.messages import HumanMessage, SystemMessage\n\n# Ensure GOOGLE_API_KEY is set in your environment variables.\n# You can also pass it directly as google_api_key='YOUR_API_KEY'.\napi_key = os.environ.get(\"GOOGLE_API_KEY\", \"\")\n\nif not api_key:\n    print(\"Warning: GOOGLE_API_KEY environment variable not set.\")\n    print(\"Please set it or pass it directly to the model constructor.\")\nelse:\n    try:\n        # Initialize the ChatGoogleGenerativeAI model\n        chat_model = ChatGoogleGenerativeAI(model=\"gemini-pro\", google_api_key=api_key)\n\n        # Prepare messages for the model\n        messages = [\n            SystemMessage(content=\"You are a helpful assistant.\"),\n            HumanMessage(content=\"What is the capital of France?\")\n        ]\n\n        # Invoke the model and print the response\n        response = chat_model.invoke(messages)\n        print(\"\\nModel Response:\", response.content)\n\n        # Example of streaming (uncomment to try)\n        # print(\"\\nStreaming Response:\")\n        # for chunk in chat_model.stream(messages):\n        #     print(chunk.content, end=\"\")\n        # print()\n\n    except Exception as e:\n        print(f\"An error occurred: {e}\")","lang":"python","description":"This quickstart demonstrates how to initialize `ChatGoogleGenerativeAI` with a Gemini model and invoke it with a simple prompt. Ensure your `GOOGLE_API_KEY` is set as an environment variable or passed directly. It also shows the basic structure for chat interactions and mentions streaming."},"warnings":[{"fix":"Set `os.environ['GOOGLE_API_KEY'] = 'YOUR_KEY'` before initialization, or pass `google_api_key='YOUR_KEY'` to `ChatGoogleGenerativeAI` or `GoogleGenerativeAI`.","message":"Authentication requires setting the `GOOGLE_API_KEY` environment variable or passing it directly to the model constructor. Alternatively, `GOOGLE_APPLICATION_CREDENTIALS` can be used for service account authentication in Google Cloud environments.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Migrate your imports from `langchain.llms.GooglePalm` to `from langchain_google_genai import GoogleGenerativeAI` and `langchain.chat_models.ChatGooglePalm` to `from langchain_google_genai import ChatGoogleGenerativeAI`.","message":"Older `GooglePalm` and `ChatGooglePalm` classes found directly in `langchain.llms` or `langchain.chat_models` are deprecated. The functionality has been moved to the `langchain-google-genai` package for better modularity and to support newer models like Gemini.","severity":"deprecated","affected_versions":"LangChain versions < 0.1.0 (for integrated classes) and all `langchain-google-genai` versions."},{"fix":"Always specify the exact model name you intend to use (e.g., `model=\"gemini-pro\"`). Refer to Google's official documentation for the latest available models and their capabilities.","message":"Model naming conventions can vary. Models like `gemini-pro`, `gemini-1.5-flash`, or specific versions like `gemini-pro-1.0` should be specified correctly. The default model may change or have different capabilities.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}