Starting April 29, 2025, Gemini 1.5 Pro and Gemini 1.5 Flash models are not available in projects that have no prior usage of these models, including new projects. For details, see Model versions and lifecycle.
Stay organized with collections
Save and categorize content based on your preferences.
publicclassVertexAIimplementsAutoCloseable
This class holds default settings and credentials to make Vertex AI API calls.
Note: The VertexAI instance will start a service client when the first API call is
made. Please close the VertexAI instance after making any API calls so that clients get closed as
well.
try(VertexAIvertexAi=newVertexAI("my-project","us-central1");){GenerativeModelmodel=newGenerativeModel("gemini-pro",vertexAi)// Do something with the model.}
Note: SDK infers location from runtime environment first. If there is no location
inferred from runtime environment, SDK will default location to us-central1.
SDK will infer projectId from runtime environment and GoogleCredentials.
Returns the PredictionServiceClient with GRPC or REST, based on the Transport type. The
client will be instantiated when the first prediction API call is made.
[[["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.32.0)\n\n public class VertexAI implements AutoCloseable\n\nThis class holds default settings and credentials to make Vertex AI API calls.\n\n**Note:** The VertexAI instance will start a service client when the first API call is\nmade. Please close the VertexAI instance after making any API calls so that clients get closed as\nwell. \n\n\n try (VertexAI vertexAi = new VertexAI(\"my-project\", \"us-central1\"); ) {\n GenerativeModel model = new GenerativeModel(\"gemini-pro\", vertexAi)\n // Do something with the model.\n }\n \nInheritance\n-----------\n\n[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \\\u003e VertexAI \n\nImplements\n----------\n\n[AutoCloseable](https://docs.oracle.com/javase/8/docs/api/java/lang/AutoCloseable.html) \n\nInherited Members\n-----------------\n\n[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) \n[Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) \n[Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) \n[Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) \n[Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) \n[Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) \n[Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) \n[Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) \n[Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) \n[Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) \n[Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)\n\nConstructors\n------------\n\n### VertexAI()\n\n public VertexAI()\n\nConstructs a VertexAI instance.\n\n**Note:** SDK infers location from runtime environment first. If there is no location\ninferred from runtime environment, SDK will default location to `us-central1`.\n\nSDK will infer projectId from runtime environment and GoogleCredentials.\n\n### VertexAI(String projectId, String location)\n\n public VertexAI(String projectId, String location)\n\nConstructs a VertexAI instance.\n\nMethods\n-------\n\n### close()\n\n public void close()\n\nCloses the VertexAI instance together with all its instantiated clients.\n\n### getApiEndpoint()\n\n public String getApiEndpoint()\n\nReturns the default endpoint to use when making API calls.\n\n### getCredentials()\n\n public Credentials getCredentials()\n\nReturns the default credentials to use when making API calls.\n\n### getHeaders()\n\n public Map\u003cString,String\u003e getHeaders()\n\nReturns the headers to use when making API calls.\n\n### getLlmUtilityClient()\n\n public LlmUtilityServiceClient getLlmUtilityClient()\n\n| **Internal Only**: This feature is not stable for application use.\n\nReturns the [LlmUtilityServiceClient](/vertex-ai/generative-ai/docs/reference/java/latest/com.google.cloud.vertexai.api.LlmUtilityServiceClient) with GRPC or REST, based on the Transport type. The\nclient will be instantiated when the first API call is made.\n\n### getLocation()\n\n public String getLocation()\n\nReturns the default location to use when making API calls.\n\n### getPredictionServiceClient()\n\n public PredictionServiceClient getPredictionServiceClient()\n\n| **Internal Only**: This feature is not stable for application use.\n\nReturns the [PredictionServiceClient](/vertex-ai/generative-ai/docs/reference/java/latest/com.google.cloud.vertexai.api.PredictionServiceClient) with GRPC or REST, based on the Transport type. The\nclient will be instantiated when the first prediction API call is made.\n\n### getProjectId()\n\n public String getProjectId()\n\nReturns the default project to use when making API calls.\n\n### getTransport()\n\n public Transport getTransport()\n\nReturns the default [Transport](/vertex-ai/generative-ai/docs/reference/java/latest/com.google.cloud.vertexai.Transport) layer to use to send API requests."]]