This package contains resources to access Google AI/ML models and other Google services via Vertex AI. Authorization to these services use service account credentials stored on the local file system or provided through the Google Cloud Platform environment it is running on.
If you are running this on a platform where the credentials cannot be provided this way, consider using the @langchain/google-vertexai-web package instead. You do not need to use both packages. See the section on Authorization below.
$ pnpm install @langchain/google-vertexai
Authorization is done through a Google Cloud Service Account.
To handle service accounts, this package uses the google-auth-library
package, and you may wish to consult the documentation for that library
about how it does so. But in short, classes in this package will use
credentials from the first of the following that apply:
apiKey attributeauthInfo attributeAPI_KEYGOOGLE_APPLICATION_CREDENTIALS environment
variable.gcloud auth application-default login, then the
default credentials.When using tools with Gemini models through Vertex AI, be aware of the following Zod schema limitations:
Discriminated Unions - .discriminatedUnion() is not supported
// ❌ This will throw an error
z.discriminatedUnion("type", [
z.object({ type: z.literal("a"), value: z.string() }),
z.object({ type: z.literal("b"), value: z.number() }),
]);
// ✅ Use a flat object with optional fields instead
z.object({
type: z.enum(["a", "b"]),
stringValue: z.string().optional(),
numberValue: z.number().optional(),
});
Union Types - z.union() is not supported
// ❌ This will throw an error
z.union([z.string(), z.number()]);
// ✅ Consider using separate optional fields
z.object({
stringValue: z.string().optional(),
numberValue: z.number().optional(),
});
Positive Refinement - .positive() is automatically converted
// ⚠️ This is automatically converted to .min(0.01)
z.number().positive();
// ✅ Prefer using .min() directly
z.number().min(0.01);
If you use unsupported schema features, you'll receive descriptive error messages:
"Gemini cannot handle union types (discriminatedUnion, anyOf, oneOf)""Failed to convert tool '[toolName]' schema for Gemini".min() instead of .positive() for number constraints