本页还没有译文
本页 30 段还没译成한국어,下面显示的是英文原文。Gemini Enterprise Agent Platform integration
还没翻译译自英文(docs.langchain.com)本页 30 段都还没译
Warning
You are currently on a page documenting the use of Gemini Enterprise Agent Platform models as text completion models. Many popular models available on Gemini Enterprise Agent Platform are chat completion models.
You may be looking for this page instead.
Gemini Enterprise Agent Platform is a service that exposes all foundation models available in Google Cloud, like gemini-2.5-pro, gemini-2.5-flash, etc.
This will help you get started with Gemini Enterprise Agent Platform completion models (LLMs) using LangChain. For detailed documentation on VertexAI features and configuration options, please refer to the API reference.
Overview
Integration details
| Class | Package | Local | Serializable | PY support | Downloads | Version |
|---|---|---|---|---|---|---|
VertexAI | @langchain/google-vertexai | ❌ | ✅ | ✅ |
Setup
LangChain.js supports two different authentication methods based on whether you're running in a Node.js environment or a web environment.
To access Gemini Enterprise Agent Platform models you'll need to create a Google Cloud Platform (GCP) account, get an API key, and install the @langchain/google-vertexai integration package. On Node.js, that package uses @langchain/google-gauth for authentication (you do not need to install it separately).
Credentials
Node.js
You should make sure the Gemini Enterprise Agent Platform API is enabled for the relevant project and that you've authenticated to Google Cloud using one of these methods:
- You are logged into an account (using
gcloud auth application-default login) permitted to that project. - You are running on a machine using a service account that is permitted to the project.
- You have downloaded the credentials for a service account that is permitted
to the project and set the
GOOGLE_APPLICATION_CREDENTIALSenvironment variable to the path of this file. or - You set the
GOOGLE_API_KEYenvironment variable to the API key for the project.
Web
To call Gemini Enterprise Agent Platform models in web environments (like Edge functions), you'll need to install
the @langchain/google-vertexai-web package.
Then, set your service account credentials in GOOGLE_WEB_CREDENTIALS (or the deprecated GOOGLE_VERTEX_AI_WEB_CREDENTIALS):
export GOOGLE_WEB_CREDENTIALS='{"type":"service_account","project_id":"YOUR_PROJECT-12345",...}'You can also pass your credentials directly in code like this:
import { VertexAI } from "@langchain/google-vertexai";
// Or uncomment this line if you're using the web version:
// import { VertexAI } from "@langchain/google-vertexai-web";
const model = new VertexAI({
authOptions: {
credentials: {"type":"service_account","project_id":"YOUR_PROJECT-12345",...},
},
});If you want to get automated tracing of your model calls you can also set your LangSmith API key by uncommenting below:
# export LANGSMITH_TRACING="true"
# export LANGSMITH_API_KEY="your-api-key"Installation
The LangChain Gemini Enterprise Agent Platform integration lives in the @langchain/google-vertexai package:
npm install @langchain/google-vertexai @langchain/coreyarn add @langchain/google-vertexai @langchain/corepnpm add @langchain/google-vertexai @langchain/coreor for web environments:
npm install @langchain/google-vertexai-web @langchain/coreyarn add @langchain/google-vertexai-web @langchain/corepnpm add @langchain/google-vertexai-web @langchain/coreInstantiation
Now we can instantiate our model object and generate chat completions:
import { VertexAI } from "@langchain/google-vertexai-web"
const llm = new VertexAI({
model: "gemini-3.8-flash",
temperature: 0,
maxRetries: 2,
// other params...
})Invocation
const inputText = "Gemini is an AI model family that "
const completion = await llm.invoke(inputText)
completionoffers a wide range of cloud computing services and artificial intelligence solutions to businesses and developers worldwide.API reference
For detailed documentation of all VertexAI features and configurations head to the API reference.