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): GenerateContentResponse

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

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

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

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

Link copied to clipboard

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

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

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