Package com.google.genai
Class ApiClient
java.lang.Object
com.google.genai.ApiClient
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
HttpApiClient,ReplayApiClient
Interface for an API client which issues HTTP requests to the GenAI APIs.
-
Method Summary
Modifier and TypeMethodDescription@Nullable StringapiKey()Returns the API key for Google AI APIs.abstract CompletableFuture<ApiResponse>asyncRequest(String httpMethod, String path, byte[] requestBytes, Optional<HttpOptions> httpOptions) Sends an asynchronous Http request given the http method, path, request bytes, and http options.abstract CompletableFuture<ApiResponse>asyncRequest(String httpMethod, String path, String requestJson, Optional<HttpOptions> httpOptions) Sends an asynchronous Http request given the http method, path, request json string, and http options.voidclose()@Nullable com.google.auth.oauth2.GoogleCredentialsReturns the GoogleCredentials for Vertex AI APIs.@Nullable StringReturns the custom base URL if provided.Returns the default environment variables for the client.okhttp3.OkHttpClientReturns the HttpClient for API calls.Returns the HTTP options for API calls.@Nullable Stringlocation()Returns the location for Vertex AI APIs.@Nullable Stringproject()Returns the project ID for Vertex AI APIs.abstract ApiResponserequest(String httpMethod, String path, byte[] requestBytes, Optional<HttpOptions> httpOptions) Sends a Http request given the http method, path, and request bytes.abstract ApiResponseSends a Http request given the http method, path, and request json string.static voidsetDefaultBaseUrls(Optional<String> geminiBaseUrl, Optional<String> vertexBaseUrl) Overrides the base URLs for the Gemini API and/or Vertex AI API.booleanvertexAI()Returns whether the client is using Vertex AI APIs.
-
Method Details
-
request
public abstract ApiResponse request(String httpMethod, String path, String requestJson, Optional<HttpOptions> httpOptions) Sends a Http request given the http method, path, and request json string. -
request
public abstract ApiResponse request(String httpMethod, String path, byte[] requestBytes, Optional<HttpOptions> httpOptions) Sends a Http request given the http method, path, and request bytes. -
asyncRequest
public abstract CompletableFuture<ApiResponse> asyncRequest(String httpMethod, String path, String requestJson, Optional<HttpOptions> httpOptions) Sends an asynchronous Http request given the http method, path, request json string, and http options. -
asyncRequest
public abstract CompletableFuture<ApiResponse> asyncRequest(String httpMethod, String path, byte[] requestBytes, Optional<HttpOptions> httpOptions) Sends an asynchronous Http request given the http method, path, request bytes, and http options. -
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 Google AI APIs. -
customBaseUrl
Returns the custom base URL if provided. -
httpClient
public okhttp3.OkHttpClient httpClient()Returns the HttpClient for API calls. -
credentials
public @Nullable com.google.auth.oauth2.GoogleCredentials credentials()Returns the GoogleCredentials for Vertex AI APIs. -
httpOptions
Returns the HTTP options for API calls. -
defaultEnvironmentVariables
Returns the default environment variables for the client. Supported environment variables:- googleApiKey -> GOOGLE_API_KEY environment variable.
- geminiApiKey -> GEMINI_API_KEY environment variable.
- project -> GOOGLE_CLOUD_PROJECT: Project ID for Vertex AI APIs.
- location -> GOOGLE_CLOUD_LOCATION: Location for Vertex AI APIs.
- vertexAI -> GOOGLE_GENAI_USE_VERTEXAI: Whether to use Vertex AI APIs(true or false).
- geminiBaseUrl -> GOOGLE_GEMINI_BASE_URL: Base URL for Gemini APIs.
- vertexBaseUrl -> GOOGLE_VERTEX_BASE_URL: Base URL for Vertex AI APIs.
-
setDefaultBaseUrls
public static void setDefaultBaseUrls(Optional<String> geminiBaseUrl, Optional<String> vertexBaseUrl) Overrides the base URLs for the Gemini API and/or Vertex AI API. -
close
public void close()- Specified by:
closein interfaceAutoCloseable
-