Package com.google.genai
Class ApiClient
java.lang.Object
com.google.genai.ApiClient
- 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.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. -
httpClient
public okhttp3.OkHttpClient httpClient()Returns the HttpClient for API calls. -
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.
-