googleapis/java-genai

Google Gen AI Java SDK provides an interface for developers to integrate Google's generative models into their Java applications.

What it solves

It provides a Java-idiomatic software development kit (SDK) for developers to interact with Google's Gemini Developer APIs and the Gemini Enterprise Agent Platform APIs, eliminating the need to write raw HTTP requests to access these generative AI models.

How it works

The SDK uses a Client class to manage connections to either the Gemini Developer backend (via API key) or the Gemini Enterprise Agent Platform (via project/location or API key). It abstracts the API calls into Java methods, allowing developers to:

  • Generate Content: Create text or multimodal responses (text and images) using unary, streaming, or asynchronous calls.
  • Configure Model Behavior: Set system instructions, safety settings, and thinking budgets via GenerateContentConfig.
  • Tool Integration: Implement automatic function calling (AFC) by passing Java methods as tools, which the SDK can execute on the client side.
  • Network Customization: Fine-tune HTTP behavior using HttpOptions (timeouts, retries, base URLs) and ClientOptions (connection pools, proxies, or custom OkHttpClient instances).

Who it’s for

Java developers who want to integrate Gemini's generative AI capabilities into their applications, whether for personal projects using the Developer API or enterprise-grade applications on the Google Cloud Platform.

Highlights

  • Dual Backend Support: Seamlessly switch between Gemini Developer and Gemini Enterprise Agent Platform APIs.
  • Automatic Function Calling: Simplifies tool use by allowing the model to trigger local Java methods automatically.
  • Flexible Execution: Supports standard, streaming, and asynchronous response patterns.
  • Structured Output: Supports JSON response schemas to ensure the model returns data in a specific format.
  • Robust Networking: Includes built-in retry logic and support for custom proxies and HTTP clients.

Related

  • Project
  • Project
  • Project
  • Project
  • Project