Class GeminiAiProvider

All Implemented Interfaces:
PropertyChangeSource, Rebindable
Direct Known Subclasses:
GeminiGoogleCloudExpressAIProvider

public class GeminiAiProvider extends AbstractAiProvider
The concrete implementation of the AbstractAgiProvider for the Google Gemini API. This class manages the native Client instance and handles the discovery and listing of available Gemini models.
Author:
anahata-gemini-pro-2.5
  • Field Details

    • client

      private transient com.google.genai.Client client
      The native Google GenAI client instance. transient to prevent serialization.
    • vertex

      private boolean vertex
      Whether this provider is configured to use Google Cloud Vertex AI instead of the standard AI Studio endpoint.
  • Constructor Details

    • GeminiAiProvider

      public GeminiAiProvider()
      Creates a new Gemini Provider with default settings.
    • GeminiAiProvider

      public GeminiAiProvider(String uuid, String displayName, boolean vertex)
      Craetes a new Gemini Provider using the Official Google Genai Java SDK.
      Parameters:
      uuid - registration id
      displayName - the human-readable display name for this provider.
      vertex - if true will point to vertex express.
  • Method Details

    • getClient

      public com.google.genai.Client getClient()
      Gets the native Gemini API client, creating it lazily if necessary.
      Returns:
      The native Client instance.
    • hokusPocus

      public void hokusPocus()
      Rotates the active key to the next available API key in the pool. Subclasses override to invalidate native API clients.

      Implementation details: Nullifies the internal Gemini client. This forces the provider to rotate to the next API key in the pool and reconstruct the client on the very next generation request.

      Overrides:
      hokusPocus in class AbstractAiProvider
    • listModels

      public List<? extends AbstractModel> listModels()
      Fetches the list of all models available from the provider's remote API.

      Implementation details: Synchronously fetches the list of available Generative Models from the Google GenAI service. Each native model is wrapped in a GeminiModel adapter.

      Specified by:
      listModels in class AbstractAiProvider
      Returns:
      A list of provider-specific AbstractModel objects.
    • getApiKeyHint

      public String getApiKeyHint()
      Gets a template or hint string to display when the API keys file is empty.

      Provides a template configuration for the Gemini api_keys.txt file.

      Specified by:
      getApiKeyHint in class AbstractAiProvider
      Returns:
      The API key hint text.