Class GeminiAPI

java.lang.Object
uno.anahata.ai.gemini.GeminiAPI

public class GeminiAPI extends Object
Manages the connection to the Gemini API, including API key rotation and model selection.

This class loads API keys from a configuration file and provides a round-robin mechanism for selecting a key for each request, helping to distribute load and stay within rate limits.

  • Constructor Details

    • GeminiAPI

      public GeminiAPI(ChatConfig config)
      Constructs a new GeminiAPI instance and loads API keys from the configuration.
      Parameters:
      config - The chat configuration.
  • Method Details

    • getClient

      public com.google.genai.Client getClient()
      Gets a new Client instance using the next available API key in the pool.
      Returns:
      A configured Gemini Client.
      Throws:
      IllegalStateException - if no API keys are available.
    • getModelId

      public String getModelId()
      Gets the currently selected model ID.
      Returns:
      The model ID.
    • setModelId

      public void setModelId(String modelId)
      Sets the model ID to be used for subsequent requests.
      Parameters:
      modelId - The new model ID.
    • getAvailableModelIds

      public List<String> getAvailableModelIds()
      Gets the list of all available model IDs.
      Returns:
      The list of model IDs.