# Class VertexAI (1.48.0)

1.48.0 (latest) 1.47.0 1.45.0 1.43.0 1.42.0 1.40.0 1.38.0 1.36.0 1.35.0 1.34.0 1.33.0 1.32.0 1.30.0 1.28.0 1.27.0 1.24.0 1.23.0 1.22.0 1.20.1 1.19.0 1.18.0 1.17.0 1.16.0 1.15.0 1.14.0 1.13.0 1.12.0 1.11.0 1.9.0 1.8.0 1.7.0 1.6.0 1.5.0 1.4.0 1.3.0 1.2.0 1.1.0 1.0.0 0.8.0 0.6.0 0.5.0 0.4.0 0.3.0 0.2.0 0.1.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](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> VertexAI

## Implements

[AutoCloseable](https://docs.oracle.com/javase/8/docs/api/java/lang/AutoCloseable.html)

## Inherited Members

[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Constructors

### VertexAI()

    public VertexAI()

Constructs a VertexAI instance.

**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.

### VertexAI(String projectId, String location)

    public VertexAI(String projectId, String location)

Constructs a VertexAI instance.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `projectId` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` the default project to use when making API calls |
| `location` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` the default location to use when making API calls |

## 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** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` | 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 to use when making API calls. |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### getHeaders()

    public Map<String,String> getHeaders()

Returns the headers to use when making API calls.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/Map.html<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html,https://docs.oracle.com/javase/8/docs/api/java/lang/String.html>` | a map of headers to use when making API calls. |

### getLlmUtilityClient()

    public LlmUtilityServiceClient getLlmUtilityClient()

> [!WARNING]
> **Internal Only**: This feature is not stable for application use.

Returns the [LlmUtilityServiceClient](https://docs.cloud.google.com/java/docs/reference/google-cloud-vertexai/latest/com.google.cloud.vertexai.api.LlmUtilityServiceClient) with GRPC or REST, based on the Transport type. The
client will be instantiated when the first API call is made.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-vertexai/latest/com.google.cloud.vertexai.api.LlmUtilityServiceClient` | [LlmUtilityServiceClient](https://docs.cloud.google.com/java/docs/reference/google-cloud-vertexai/latest/com.google.cloud.vertexai.api.LlmUtilityServiceClient) that makes calls to the backing service through method calls that map to the API methods. |

### getLocation()

    public String getLocation()

Returns the default location to use when making API calls.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` | Location in string format. |

### getPredictionServiceClient()

    public PredictionServiceClient getPredictionServiceClient()

> [!WARNING]
> **Internal Only**: This feature is not stable for application use.

Returns the [PredictionServiceClient](https://docs.cloud.google.com/java/docs/reference/google-cloud-vertexai/latest/com.google.cloud.vertexai.api.PredictionServiceClient) with GRPC or REST, based on the Transport type. The
client will be instantiated when the first prediction API call is made.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-vertexai/latest/com.google.cloud.vertexai.api.PredictionServiceClient` | [PredictionServiceClient](https://docs.cloud.google.com/java/docs/reference/google-cloud-vertexai/latest/com.google.cloud.vertexai.api.PredictionServiceClient) that send requests to the backing service through method calls that map to the API methods. |

### getProjectId()

    public String getProjectId()

Returns the default project to use when making API calls.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` | Project ID in string format. |

### getTransport()

    public Transport getTransport()

Returns the default [Transport](https://docs.cloud.google.com/java/docs/reference/google-cloud-vertexai/latest/com.google.cloud.vertexai.Transport) layer to use to send API requests.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-vertexai/latest/com.google.cloud.vertexai.Transport` | [Transport](https://docs.cloud.google.com/java/docs/reference/google-cloud-vertexai/latest/com.google.cloud.vertexai.Transport) layer used when sending API requests. |