Chat

class Chat

A multi-turn chat session with a generative model.

Obtain a session from Chats.create:

val chat = client.chats.create(model = "gemini-3.6-flash")

A session is not safe for concurrent turns: start a turn only once the previous one has finished, or the turns will not see one another. getHistory is safe to call at any time.

Functions

Link copied to clipboard
fun getHistory(curated: Boolean = false): List<Content>

Returns a snapshot of the turns in this session.

Link copied to clipboard
suspend fun sendMessage(content: Content, config: GenerateContentConfig? = null, automaticFunctionCalling: AutomaticFunctionCalling? = null): GenerateContentResponse

Sends content as the next turn and returns the model's response.

suspend fun sendMessage(text: String, config: GenerateContentConfig? = null, automaticFunctionCalling: AutomaticFunctionCalling? = null): GenerateContentResponse

Sends text as the next turn and returns the model's response.

suspend fun sendMessage(contents: List<Content>, config: GenerateContentConfig? = null, automaticFunctionCalling: AutomaticFunctionCalling? = null): GenerateContentResponse

Sends contents as the next turn and returns the model's response.

Link copied to clipboard
fun sendMessageStream(content: Content, config: GenerateContentConfig? = null, automaticFunctionCalling: AutomaticFunctionCalling? = null): Flow<GenerateContentResponse>

Sends content as the next turn and returns the model's response in chunks.

fun sendMessageStream(text: String, config: GenerateContentConfig? = null, automaticFunctionCalling: AutomaticFunctionCalling? = null): Flow<GenerateContentResponse>

Sends text as the next turn and returns the model's response in chunks.

fun sendMessageStream(contents: List<Content>, config: GenerateContentConfig? = null, automaticFunctionCalling: AutomaticFunctionCalling? = null): Flow<GenerateContentResponse>

Sends contents as the next turn and returns the model's response in chunks.