Method Signature
Parameters
The model to use for the chat session.Example:
'gemini-2.0-flash' or 'gemini-1.5-pro'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 responsetop_p: Nucleus sampling parametertop_k: Top-k sampling parametersystem_instruction: System-level instructions
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.)
Returns
A Chat object that maintains conversation state and provides methods to send messages:
send_message(): Send a message and get the complete responsesend_message_stream(): Send a message and stream the responseget_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.
Related Methods
- chat.send_message - Send messages in the chat session
- models.generate_content - Single-turn generation without chat state