Class VertexAI (0.5.0)

public class VertexAI implements AutoCloseable

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 (VertexAI vertexAi = new VertexAI("my-project", "us-central1"); ) {
   GenerativeModel model = new GenerativeModel("gemini-pro", vertexAi)
   // Do something with the model.
 }
 

Inheritance

java.lang.Object > VertexAI

Implements

AutoCloseable

Constructors

VertexAI(String projectId, String location)

public VertexAI(String projectId, String location)

Construct a VertexAI instance.

Parameters
Name Description
projectId String

the default project to use when making API calls

location String

the default location to use when making API calls

VertexAI(String projectId, String location, Credentials credentials)

public VertexAI(String projectId, String location, Credentials credentials)

Construct a VertexAI instance with custom credentials.

Parameters
Name Description
projectId String

the default project to use when making API calls

location String

the default location to use when making API calls

credentials com.google.auth.Credentials

the custom credentials to use when making API calls

VertexAI(String projectId, String location, Transport transport)

public VertexAI(String projectId, String location, Transport transport)

Construct a VertexAI instance with default transport layer.

Parameters
Name Description
projectId String

the default project to use when making API calls

location String

the default location to use when making API calls

transport Transport

the default Transport layer to use to send API requests

VertexAI(String projectId, String location, Transport transport, Credentials credentials)

public VertexAI(String projectId, String location, Transport transport, Credentials credentials)

Construct a VertexAI instance with default transport layer and custom credentials.

Parameters
Name Description
projectId String

the default project to use when making API calls

location String

the default location to use when making API calls

transport Transport

the default Transport layer to use to send API requests

credentials com.google.auth.Credentials

the default custom credentials to use when making API calls

VertexAI(String projectId, String location, Transport transport, String[] scopes) (deprecated)

public VertexAI(String projectId, String location, Transport transport, String[] scopes)

Deprecated. Use <xref uid="#VertexAI(String, String, Transport, List<String>)" data-throw-if-not-resolved="false">#VertexAI(String, String, Transport, List<String>) instead.

Construct a VertexAI instance with default transport layer and application default credentials.

Parameters
Name Description
projectId String

the default project to use when making API calls

location String

the default location to use when making API calls

transport Transport

the default Transport layer to use to send API requests

scopes String[]

collection of scopes in the default credentials

VertexAI(String projectId, String location, Transport transport, List<String> scopes)

public VertexAI(String projectId, String location, Transport transport, List<String> scopes)

Construct a VertexAI instance with default transport layer and application default credentials.

Parameters
Name Description
projectId String

the default project to use when making API calls

location String

the default location to use when making API calls

transport Transport

the default Transport layer to use to send API requests

scopes List<String>

List of scopes in the default credentials. Make sure you have specified "https://www.googleapis.com/auth/cloud-platform" scope to access resources on Vertex AI.

VertexAI(String projectId, String location, String[] scopes) (deprecated)

public VertexAI(String projectId, String location, String[] scopes)

Deprecated. Use <xref uid="#VertexAI(String, String, List<String>)" data-throw-if-not-resolved="false">#VertexAI(String, String, List<String>) instead.

Construct a VertexAI instance with application default credentials.

Parameters
Name Description
projectId String

the default project to use when making API calls

location String

the default location to use when making API calls

scopes String[]

collection of scopes in the default credentials. Make sure you have specified "https://www.googleapis.com/auth/cloud-platform" scope to access resources on Vertex AI.

VertexAI(String projectId, String location, List<String> scopes)

public VertexAI(String projectId, String location, List<String> scopes)

Construct a VertexAI instance with application default credentials.

Parameters
Name Description
projectId String

the default project to use when making API calls

location String

the default location to use when making API calls

scopes List<String>

List of scopes in the default credentials. Make sure you have specified "https://www.googleapis.com/auth/cloud-platform" scope to access resources on Vertex AI.

Methods

close()

public void close()

Closes the VertexAI instance together with all its instantiated clients.

getApiEndpoint()

public String getApiEndpoint()

Returns the default endpoint to use when making API calls.

Returns
Type Description
String

API endpoint in string format.

getCredentials()

public Credentials getCredentials()

Returns the default credentials to use when making API calls.

Returns
Type Description
com.google.auth.Credentials

Credentials if the user has provided either scopes or credentials to the VertexAI object.

Exceptions
Type Description
IOException

getLlmUtilityClient()

public LlmUtilityServiceClient getLlmUtilityClient()

Returns the LlmUtilityServiceClient with GRPC. The client will be instantiated when the first prediction API call is made.

Returns
Type Description
LlmUtilityServiceClient

LlmUtilityServiceClient that makes gRPC calls to the backing service through method calls that map to the API methods.

Exceptions
Type Description
IOException

getLlmUtilityRestClient()

public LlmUtilityServiceClient getLlmUtilityRestClient()

Returns the LlmUtilityServiceClient with REST. The client will be instantiated when the first prediction API call is made.

Returns
Type Description
LlmUtilityServiceClient

LlmUtilityServiceClient that makes REST requests to the backing service through method calls that map to the API methods.

Exceptions
Type Description
IOException

getLocation()

public String getLocation()

Returns the default location to use when making API calls.

Returns
Type Description
String

Location in string format.

getPredictionServiceClient()

public PredictionServiceClient getPredictionServiceClient()

Returns the PredictionServiceClient with GRPC. The client will be instantiated when the first prediction API call is made.

Returns
Type Description
PredictionServiceClient
Exceptions
Type Description
IOException

getPredictionServiceRestClient()

public PredictionServiceClient getPredictionServiceRestClient()

Returns the PredictionServiceClient with REST. The client will be instantiated when the first prediction API call is made.

Returns
Type Description
PredictionServiceClient

PredictionServiceClient that send REST requests to the backing service through method calls that map to the API methods.

Exceptions
Type Description
IOException

getProjectId()

public String getProjectId()

Returns the default project to use when making API calls.

Returns
Type Description
String

Project ID in string format.

getTransport()

public Transport getTransport()

Returns the default Transport layer to use to send API requests.

Returns
Type Description
Transport

Transport layer used when sending API requests.

setApiEndpoint(String apiEndpoint)

public void setApiEndpoint(String apiEndpoint)

Sets the value for #getApiEndpoint().

Parameter
Name Description
apiEndpoint String

setTransport(Transport transport)

public void setTransport(Transport transport)

Sets the value for #getTransport().

Parameter
Name Description
transport Transport