Class Client

java.lang.Object
com.google.genai.Client
All Implemented Interfaces:
AutoCloseable

public final class Client extends Object implements AutoCloseable
Client class for GenAI. This class is thread-safe.
  • Field Details

    • models

      public final Models models
    • batches

      public final Batches batches
    • caches

      public final Caches caches
    • operations

      public final Operations operations
    • chats

      public final Chats chats
    • files

      public final Files files
    • async

      public final Client.Async async
    • authTokens

      public final Tokens authTokens
    • tunings

      public final Tunings tunings
    • fileSearchStores

      public final FileSearchStores fileSearchStores
    • interactions

      public final Interactions interactions
    • agents

      public final Agents agents
    • webhooks

      public final Webhooks webhooks
    • environments

      public final Environments environments
    • triggers

      public final Triggers triggers
    • credentials

      public final Credentials credentials
    • voices

      public final Voices voices
    • decisions

      public final Decisions decisions
  • Constructor Details

    • Client

      public Client()
      Constructs a Client instance with environment variables.
  • Method Details

    • builder

      public static Client.Builder builder()
      Returns a Client.Builder for Client.
    • vertexAI

      public boolean vertexAI()
      Returns whether the client is using the Gemini Enterprise API. Prefer enterprise().
    • enterprise

      public boolean enterprise()
      Returns whether the client is using the Gemini Enterprise API.
    • isDefaultApiVersion

      public boolean isDefaultApiVersion()
      Returns true if no API version was configured via HttpOptions.apiVersion() or the GOOGLE_GENAI_API_VERSION environment variable, so the client is using the SDK's default API version for its backend.
    • project

      public String project()
      Returns the project ID for the Gemini Enterprise API.
    • location

      public String location()
      Returns the location for the Gemini Enterprise API.
    • apiKey

      public String apiKey()
      Returns the API key for the Gemini Developer API or the Gemini Enterprise API.
    • close

      public void close()
      Closes the Client instance together with its instantiated http client.
      Specified by:
      close in interface AutoCloseable
    • setDefaultBaseUrls

      public static void setDefaultBaseUrls(Optional<String> geminiBaseUrl, Optional<String> vertexBaseUrl)
      Overrides the base URLs for the Gemini Developer API and/or the Gemini Enterprise 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.