Class ApiClient

java.lang.Object
com.google.genai.ApiClient
Direct Known Subclasses:
HttpApiClient, ReplayApiClient

@InternalApi public abstract class ApiClient extends Object
Interface for an API client which issues HTTP requests to the GenAI 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

      public @Nullable String project()
      Returns the project ID for Vertex AI APIs.
    • location

      public @Nullable String location()
      Returns the location for Vertex AI APIs.
    • apiKey

      public @Nullable String apiKey()
      Returns the API key for Google AI APIs.
    • httpClient

      public okhttp3.OkHttpClient httpClient()
      Returns the HttpClient for API calls.
    • httpOptions

      public HttpOptions httpOptions()
      Returns the HTTP options for API calls.
    • defaultEnvironmentVariables

      public static com.google.common.collect.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

      public static void setDefaultBaseUrls(Optional<String> geminiBaseUrl, Optional<String> vertexBaseUrl)
      Overrides the base URLs for the Gemini API and/or Vertex AI API.