Documentation Index
Fetch the complete documentation index at: https://mintlify.com/googleapis/python-genai/llms.txt
Use this file to discover all available pages before exploring further.
Method Signature
Description
Makes an API request to generate content using a Gemini model. Supports text-only and multimodal input/output, including images, audio, and video. The method includes built-in support for automatic function calling (AFC) when tools are provided. MCP (Model Context Protocol) support is available as an experimental feature.Parameters
The model to use for generation.Vertex AI formats:
- Model ID:
'gemini-2.0-flash' - Full resource name:
'projects/my-project/locations/us-central1/publishers/google/models/gemini-2.0-flash' - Partial resource name:
'publishers/google/models/gemini-2.0-flash' - Publisher/model:
'google/gemini-2.0-flash'
- Model ID:
'gemini-2.0-flash' - Model name:
'models/gemini-2.0-flash' - Tuned model:
'tunedModels/1234567890123456789'
The conversation history or input prompt to generate content from.Can be:
- A string:
'What is your name?' - A list of Content objects
- A list of Part objects
- Mixed content with text, images, video, and audio
Configuration for content generation.
Response
List of generated response candidates
Token usage information
Feedback about the prompt (e.g., safety blocks)
The model version used
Convenience property: text from the first candidate
Code Examples
Basic Text Generation
Multimodal Generation (Image Input)
Structured JSON Output
Function Calling (Automatic)
Async Usage
Notes
- The method automatically handles function calling when Python callables are provided in
tools - MCP (Model Context Protocol) sessions are only supported in async methods
- Use
generate_content_streamfor streaming responses - Multimodal input is supported for Gemini 2.0 and later models
- Some configuration options are only available on Vertex AI or Gemini API
Related Methods
- generate_content_stream - Streaming version
- count_tokens - Count tokens before generating
- embed_content - Generate embeddings