googleapis/java-genai
Google Gen AI Java SDK provides an interface for developers to integrate Google's generative models into their Java applications.
Google Gen AI Java SDK
What it is – An official Java client library that lets you call Google’s Gemini large‑language‑model APIs (the public Gemini Developer API and the Gemini Enterprise Agent Platform) from Java code.
Key capabilities
- Simple
Clientbuilder to configure API key, GCP project/location, or “enterprise” mode. - Supports the main Gemini endpoints:
generateContent(text, multimodal, streaming, async), token‑counting, and video generation. - Configuration objects for fine‑grained HTTP control (
HttpOptions,HttpRetryOptions,ClientOptions), including custom OkHttp client, proxy, time‑outs, and retry policies. - Advanced model options via
GenerateContentConfig: system instructions, safety settings, tool use (Google Search, automatic function calling), response schema, token limits, and thinking budget. - Automatic function calling (AFC) – expose Java static methods as tools that the model can invoke.
- Stream and async APIs for low‑latency or non‑blocking use.
- Maven artifact
com.google.genai:google-genai(current 1.77.0, Java 17+ required from v2.0.0).
Typical usage flow
- Add the Maven dependency.
- Set
GOOGLE_API_KEY(or project/location env vars for Enterprise mode) or pass them toClient.builder(). - Create a
Clientinstance. - Call
client.models.generateContent(modelName, prompt, config)(or the streaming/async variants). - Optionally customise HTTP behaviour or enable tools/safety via the config objects.
Who it’s for – Java developers who want to integrate Gemini LLM capabilities—text generation, multimodal image description, function calling, or structured JSON output—into backend services, desktop apps, or Android‑style JVM projects without handling raw HTTP calls.
Limitations / upcoming changes
- In the next major version AFC will move from
Models.generate_contentto theChatsmodule. - Java 17 becomes the minimum supported version from SDK 2.0.0; pin the version if you need older JDKs.
Where to learn more – The repository’s README links to Maven badge, Javadoc, and example code under examples/ for each feature.
Related
- Project
- Project
- Project
- Project
- Project