Gemini

class Gemini : Model

Implementation of Model that interacts with Google Gemini models using the GenAI SDK.

This class provides functionality to generate content from Gemini models, supporting both unary and streaming responses. It can be configured to use either a Google AI API key or Vertex AI credentials for authentication.

GenAI SDK based Gemini currently prevents usage of API_KEY and GoogleCredentials on Android. Use Firebase AI instead.

Constructors

Link copied to clipboard
constructor(client: Client, name: String, speechConfig: SpeechConfig? = null)

Creates a Gemini from a preconfigured GenAI SDK Client, for callers that need a custom transport or auth.

constructor(name: String, apiKey: String? = null, speechConfig: SpeechConfig? = null)

Creates a Gemini instance using a Google AI API key for authentication. Its client retries transient failures with the GenAI SDK's default retry options; pass your own Client for other retry settings.

constructor(name: String, vertexCredentials: VertexCredentials, speechConfig: SpeechConfig? = null)

Creates a Gemini instance using Vertex AI credentials for authentication. Its client retries transient failures with the GenAI SDK's default retry options; pass your own Client for other retry settings.

Types

Link copied to clipboard
class Builder

Fluent builder for Gemini, provided primarily for Java callers. Any property left unset falls back to the same default as the constructor.

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val name: String

The name of the model.

Link copied to clipboard

The speech config for live sessions opened by this model. When set, it replaces the request's own speech config at connect, as in ADK Python.

Functions

Link copied to clipboard
open suspend override fun connect(request: LlmRequest): LiveConnection

Opens a live session configured by LlmRequest.liveConnectConfig (using request.model when set), returning once the server confirms setup and throwing if the server refuses it. If the caller is cancelled while the session opens, the session is closed in the background. Reconnection is not handled here, though a Vertex AI resume with transparent unset asks for transparent resumption.

Link copied to clipboard
open override fun generateContent(request: LlmRequest, stream: Boolean = false): Flow<LlmResponse>

Generates content for the given LlmRequest. This returns a Flow of LlmResponses.