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")Content copied to clipboard
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
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.
suspend fun sendMessage(text: String, config: GenerateContentConfig? = null): GenerateContentResponse
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
fun sendMessageStream(content: Content, config: GenerateContentConfig? = null): Flow<GenerateContentResponse>
Sends content as the next turn and returns the model's response in chunks.
fun sendMessageStream(text: String, config: GenerateContentConfig? = 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): Flow<GenerateContentResponse>
Sends contents as the next turn and returns the model's response in chunks.