Package com.google.genai
Class Client
java.lang.Object
com.google.genai.Client
- All Implemented Interfaces:
AutoCloseable
Client class for GenAI. This class is thread-safe.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionfinal class
Async class for GenAI.static class
Builder forClient
. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapiKey()
Returns the API key for Gemini API.static Client.Builder
builder()
Returns aClient.Builder
forClient
.void
close()
Closes the Client instance together with its instantiated http client.location()
Returns the location for Vertex AI APIs.project()
Returns the project ID for Vertex AI APIs.static void
setDefaultBaseUrls
(Optional<String> geminiBaseUrl, Optional<String> vertexBaseUrl) Overrides the base URLs for the Gemini API and/or Vertex AI API.boolean
vertexAI()
Returns whether the client is using Vertex AI APIs.
-
Field Details
-
models
-
batches
-
caches
-
operations
-
chats
-
files
-
async
-
tunings
-
-
Constructor Details
-
Client
public Client()Constructs a Client instance with environment variables.
-
-
Method Details
-
builder
Returns aClient.Builder
forClient
. -
vertexAI
public boolean vertexAI()Returns whether the client is using Vertex AI APIs. -
project
Returns the project ID for Vertex AI APIs. -
location
Returns the location for Vertex AI APIs. -
apiKey
Returns the API key for Gemini API. -
close
public void close()Closes the Client instance together with its instantiated http client.- Specified by:
close
in interfaceAutoCloseable
-
setDefaultBaseUrls
public static void setDefaultBaseUrls(Optional<String> geminiBaseUrl, Optional<String> vertexBaseUrl) Overrides the base URLs for the Gemini API and/or Vertex AI API.Note: This function should be called before initializing the SDK. If the base URLs are set after initializing the SDK, the base URLs will not be updated.
Precedence rule for base URL:
1. Base URL set via HttpOptions.
2. Base URL set via the latest call to setDefaultBaseUrls.
3. Base URL set via environment variables GOOGLE_GEMINI_BASE_URL or GOOGLE_VERTEX_BASE_URL.
-