Skip to main content
Creates a new chat session to have multi-turn conversations with the model.

Method Signature

Parameters

string
required
The model to use for the chat session.Example: 'gemini-2.0-flash' or 'gemini-1.5-pro'
GenerateContentConfig
Configuration for the generate content requests in this chat session.This config will be used as the default for all messages sent in the chat unless overridden in individual send_message() or send_message_stream() calls.Common config options:
  • temperature: Controls randomness (0.0 to 2.0)
  • max_output_tokens: Maximum tokens in response
  • top_p: Nucleus sampling parameter
  • top_k: Top-k sampling parameter
  • system_instruction: System-level instructions
list[Content]
Previous conversation history to initialize the chat with.Each Content object should have:
  • role: Either "user" or "model"
  • parts: List of content parts (text, images, etc.)
If not provided, starts with an empty history.

Returns

Chat
A Chat object that maintains conversation state and provides methods to send messages:
  • send_message(): Send a message and get the complete response
  • send_message_stream(): Send a message and stream the response
  • get_history(): Get the conversation history

Examples

Basic Chat Session

Chat with Configuration

Chat with History

Async Chat Session

API Availability

This method is available in both Gemini API and Vertex AI.