Client

The main entry point for the Google Gen AI SDK.

Note on Mobile Security: While this SDK supports Android targets via Kotlin Multiplatform, it is intended for server-side use or secure backend environments. We strongly discourage embedding API keys or Google Cloud IAM credentials (such as Service Account JSON keys or OAuth tokens) directly into public mobile client applications without protection. For public mobile apps connecting directly from client devices, please use Firebase AI Logic with Firebase App Check enabled.

Usage:

val client = Client(apiKey = "YOUR_API_KEY")
val response = client.models.generateContent("gemini-3.5-flash", "Hello, world!")
println(response.text)

Constructors

Link copied to clipboard
constructor(apiKey: String? = null, project: String? = null, location: String? = null, credentials: GoogleCredentials? = null, enterprise: Boolean? = null, httpOptions: HttpOptions? = null)

Constructs a Client instance for either Gemini API or Gemini Enterprise Agent Platform API.

Properties

Link copied to clipboard

The API key used for authentication with Gemini API or Gemini Enterprise Agent Platform API.

Link copied to clipboard

Service for interacting with Caches API.

Link copied to clipboard

Whether the client is configured to use Gemini Enterprise Agent Platform API.

Link copied to clipboard

The Google Cloud location used for Gemini Enterprise Agent Platform API.

Link copied to clipboard

Service for interacting with Models API.

Link copied to clipboard

The Google Cloud project ID used for Gemini Enterprise Agent Platform API.

Functions

Link copied to clipboard
open override fun close()

Closes the Client instance and its underlying HTTP client.