Class ApiClient
-
- All Implemented Interfaces:
-
java.lang.AutoCloseable
@InternalApi() public abstract class ApiClient implements AutoCloseable
Interface for an API client which issues HTTP requests to the GenAI APIs.
-
-
Method Summary
Modifier and Type Method Description abstract ApiResponserequest(String httpMethod, String path, String requestJson, Optional<HttpOptions> httpOptions)Sends a Http request given the http method, path, and request json string. abstract ApiResponserequest(String httpMethod, String path, Array<byte> requestBytes, Optional<HttpOptions> httpOptions)Sends a Http request given the http method, path, and request bytes. 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. abstract CompletableFuture<ApiResponse>asyncRequest(String httpMethod, String path, Array<byte> requestBytes, Optional<HttpOptions> httpOptions)Sends an asynchronous Http request given the http method, path, request bytes, and http options. booleanvertexAI()Returns whether the client is using Vertex AI APIs. Stringproject()Returns the project ID for Vertex AI APIs. Stringlocation()Returns the location for Vertex AI APIs. StringapiKey()Returns the API key for Google AI APIs. StringcustomBaseUrl()Returns the custom base URL if provided. OkHttpClienthttpClient()Returns the HttpClient for API calls. GoogleCredentialscredentials()Returns the GoogleCredentials for Vertex AI APIs. HttpOptionshttpOptions()Returns the HTTP options for API calls. static ImmutableMap<String, String>defaultEnvironmentVariables()Returns the default environment variables for the client. static voidsetDefaultBaseUrls(Optional<String> geminiBaseUrl, Optional<String> vertexBaseUrl)Overrides the base URLs for the Gemini API and/or Vertex AI API. voidclose()-
-
Method Detail
-
request
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
abstract ApiResponse request(String httpMethod, String path, Array<byte> requestBytes, Optional<HttpOptions> httpOptions)
Sends a Http request given the http method, path, and request bytes.
-
asyncRequest
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
abstract CompletableFuture<ApiResponse> asyncRequest(String httpMethod, String path, Array<byte> requestBytes, Optional<HttpOptions> httpOptions)
Sends an asynchronous Http request given the http method, path, request bytes, and http options.
-
vertexAI
boolean vertexAI()
Returns whether the client is using Vertex AI APIs.
-
customBaseUrl
@Nullable() String customBaseUrl()
Returns the custom base URL if provided.
-
httpClient
OkHttpClient httpClient()
Returns the HttpClient for API calls.
-
credentials
@Nullable() GoogleCredentials credentials()
Returns the GoogleCredentials for Vertex AI APIs.
-
httpOptions
HttpOptions httpOptions()
Returns the HTTP options for API calls.
-
defaultEnvironmentVariables
static ImmutableMap<String, String> 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
static void setDefaultBaseUrls(Optional<String> geminiBaseUrl, Optional<String> vertexBaseUrl)
Overrides the base URLs for the Gemini API and/or Vertex AI API.
-
close
void close()
-
-
-
-