Gemini

class Gemini(apiKey: String, client: HttpClient? = null, fileUploadProvider: FileUploadProvider? = null)

Represents a client for interacting with the Gemini API, providing methods to extract content, embed content, and retrieve model information.

Constructors

Link copied to clipboard
constructor(apiKey: String, client: HttpClient? = null, fileUploadProvider: FileUploadProvider? = null)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
suspend fun batchEmbedContents(inputJson: BatchEmbedRequest, model: String = "embedding-001"): BatchEmbedResponse

Embeds contents in batch using the embedding-001 model.

Link copied to clipboard
suspend fun countTokens(inputJson: CountTokensRequest, model: String = "gemini-2.0-flash-lite"): TotalTokens

Counts the number of tokens in the provided text using a specified model.

Link copied to clipboard

Creates a new cached content entry in the system.

Link copied to clipboard
suspend fun deleteCachedContent(name: String)

Deletes a specific cached content entry by name.

Link copied to clipboard
suspend fun deleteContent(urlStr: String)

Sends a DELETE request to the specified URL to delete content.

Link copied to clipboard
suspend fun embedContent(inputJson: EmbedContentRequest, model: String = "embedding-001"): EmbedResponse

Embeds content using the embedding-001 model.

Link copied to clipboard
suspend fun generateContent(inputJson: GenerateContentRequest, model: String = "gemini-pro"): GenerateContentResponse

Generates content based on the provided input JSON using a specified model.

Link copied to clipboard
suspend fun getCachedContent(name: String): CachedContent

Fetches cached content by name.

Link copied to clipboard
suspend fun getContent(urlStr: String, inputJson: String? = null): String

Performs a POST request to the specified URL string with the given input JSON payload.

Link copied to clipboard
fun Gemini.getLiveClient(model: String, config: LiveConnectConfig? = null): GeminiLive

Creates a client for the Live API.

Link copied to clipboard
suspend fun getModels(): ModelCollection

Retrieves a collection of models available in the Gemini API.

Link copied to clipboard
suspend fun listCachedContent(pageSize: Int = 1000, pageToken: String? = null): CachedContentList

Retrieves a list of cached content entries.

Link copied to clipboard
fun streamGenerateContent(inputJson: GenerateContentRequest, model: String = "gemini-pro"): Flow<GenerateContentResponse>

Generates content stream based on the provided input JSON using a specified model.

Link copied to clipboard
suspend fun uploadFile(file: Path, mimeType: String, displayName: String): GeminiFile

Uploads a file to the Gemini API.