TheVertexAIclass is the base class for authenticating to Vertex AI. To use Vertex AI's generative AI models, use thegetGenerativeModelmethod. To use generative AI features that are in Preview, use thepreviewnamespace.
This method creates a new instance of theGenerativeModelclass with the platform initialization parameters provided inVertexInitand model initialization parameters provided inModelParams. You can optionally provideRequestOptionsto override the default request options.
constproject='your-cloud-project';constlocation='us-central1';consttextModel='gemini-1.0-pro';constvisionModel='gemini-1.0-pro-vision';constvertexAI=newVertexAI({project:project,location:location});// Instantiate modelsconstgenerativeModel=vertexAI.getGenerativeModel({model:textModel,// The following parameters are optional// They can also be passed to individual content generation requestssafetySettings:[{category:HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,threshold:HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE}],generationConfig:{maxOutputTokens:256},});constgenerativeVisionModel=vertexAI.getGenerativeModel({model:visionModel,});constgenerativeModelPreview=vertexAI.preview.getGenerativeModel({model:textModel,});
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Class VertexAI (1.10.0)\n\nVersion latestkeyboard_arrow_down\n\n- [1.10.0 (latest)](/nodejs/docs/reference/vertexai/latest/vertexai/vertexai)\n- [1.9.0](/nodejs/docs/reference/vertexai/1.9.0/vertexai/vertexai)\n- [1.8.1](/nodejs/docs/reference/vertexai/1.8.1/vertexai/vertexai)\n- [1.7.0](/nodejs/docs/reference/vertexai/1.7.0/vertexai/vertexai)\n- [1.6.0](/nodejs/docs/reference/vertexai/1.6.0/vertexai/vertexai)\n- [1.5.0](/nodejs/docs/reference/vertexai/1.5.0/vertexai/vertexai)\n- [1.4.1](/nodejs/docs/reference/vertexai/1.4.1/vertexai/vertexai)\n- [1.3.1](/nodejs/docs/reference/vertexai/1.3.1/vertexai/vertexai)\n- [1.2.0](/nodejs/docs/reference/vertexai/1.2.0/vertexai/vertexai)\n- [1.1.0](/nodejs/docs/reference/vertexai/1.1.0/vertexai/vertexai)\n- [1.0.0](/nodejs/docs/reference/vertexai/1.0.0/vertexai/vertexai)\n- [0.5.0](/nodejs/docs/reference/vertexai/0.5.0/vertexai/vertexai)\n- [0.4.0](/nodejs/docs/reference/vertexai/0.4.0/vertexai/vertexai)\n- [0.3.1](/nodejs/docs/reference/vertexai/0.3.1/vertexai/vertexai)\n- [0.2.1](/nodejs/docs/reference/vertexai/0.2.1/vertexai/vertexai) \nThe `VertexAI` class is the base class for authenticating to Vertex AI. To use Vertex AI's generative AI models, use the `getGenerativeModel` method. To use generative AI features that are in Preview, use the `preview` namespace.\n\nPackage\n-------\n\n[@google-cloud/vertexai](../overview.html)\n\nConstructors\n------------\n\n### (constructor)(init)\n\n constructor(init: VertexInit);\n\nConstructs a new instance of the `VertexAI` class\n\nProperties\n----------\n\n### preview\n\n readonly preview: VertexAIPreview;\n\nMethods\n-------\n\n### getGenerativeModel(modelParams, requestOptions)\n\n getGenerativeModel(modelParams: ModelParams, requestOptions?: RequestOptions): GenerativeModel;\n\nGets the GenerativeModel class instance.\n\nThis method creates a new instance of the `GenerativeModel` class with the platform initialization parameters provided in [VertexInit](/nodejs/docs/reference/vertexai/latest/vertexai/vertexinit) and model initialization parameters provided in [ModelParams](/nodejs/docs/reference/vertexai/latest/vertexai/modelparams). You can optionally provide [RequestOptions](/nodejs/docs/reference/vertexai/latest/vertexai/requestoptions) to override the default request options.\n\n**Example** \n\n\n const project = 'your-cloud-project';\n const location = 'us-central1';\n const textModel = 'gemini-1.0-pro';\n const visionModel = 'gemini-1.0-pro-vision';\n\n const vertexAI = new VertexAI({project: project, location: location});\n\n // Instantiate models\n const generativeModel = vertexAI.getGenerativeModel({\n model: textModel,\n // The following parameters are optional\n // They can also be passed to individual content generation requests\n safetySettings: [{\n category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,\n threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE\n }],\n generationConfig: {maxOutputTokens: 256},\n });\n\n const generativeVisionModel = vertexAI.getGenerativeModel({\n model: visionModel,\n });\n\n const generativeModelPreview = vertexAI.preview.getGenerativeModel({\n model: textModel,\n });\n\n### getLocation()\n\n protected getLocation(): string;\n\n### getProject()\n\n protected getProject(): string;"]]