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)]
- 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 randomnessmax_output_tokens: Maximum response lengthtop_p,top_k: Sampling parametersresponse_mime_type: Output format (e.g.,"application/json")
Returns
send_message
GenerateContentResponse
The complete model response containing:
text: The response textcandidates: List of response candidatesusage_metadata: Token usage informationmodel_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.
Related Methods
- chats.create - Create a new chat session
- models.generate_content - Single-turn generation