Skip to main content
Sends a message in the chat session and receives the model’s response. The chat maintains conversation history automatically.

Method Signatures

send_message (Non-streaming)

send_message_stream (Streaming)

Parameters

string | Part | list[Part]
required
The message to send to the model.Can be:
  • A simple string: "Tell me a story"
  • A Part object: Part(text="Hello")
  • A list of Parts: [Part(text="Describe this:"), Part(inline_data=image)]
Supported part types:
  • Text
  • Images (PIL Image, bytes, or file data)
  • Video
  • Audio
  • File references
GenerateContentConfig
Optional configuration to override the chat’s default config for this specific request.Common options:
  • temperature: Controls randomness
  • max_output_tokens: Maximum response length
  • top_p, top_k: Sampling parameters
  • response_mime_type: Output format (e.g., "application/json")

Returns

send_message

GenerateContentResponse
The complete model response containing:
  • text: The response text
  • candidates: List of response candidates
  • usage_metadata: Token usage information
  • model_version: The model version used

send_message_stream

Iterator[GenerateContentResponse]
An iterator that yields response chunks as they’re generated.Each chunk contains partial content that can be displayed incrementally.

Examples

Basic Text Message

Streaming Response

Message with Image

Override Configuration

Multi-turn Conversation

JSON Output

Async Streaming

File Upload in Chat

Access Chat History

Error Handling

API Availability

These methods are available in both Gemini API and Vertex AI.