Overview
Thetypes module provides the core type system for the Google Gen AI SDK. It includes Pydantic models and TypedDict definitions for all API request and response objects.
Importing Types
Types can be imported directly from the main package:Pydantic Models vs TypedDict
The SDK provides two ways to work with types:Pydantic Models
Pydantic models provide validation, type checking, and convenient methods:- Runtime validation
- Type safety
- Helper methods and constructors
- Serialization/deserialization
TypedDict
TypedDict definitions provide type hints for dictionaries:- Lighter weight
- More flexible
- Compatible with JSON serialization
- Editor autocomplete
Union Types
Many parameters accept union types for flexibility:Key Type Categories
Content Types
Types for representing messages and content:- Content - Multi-part message content
- Part - Individual content parts
- UserContent - Content from the user
- ModelContent - Content from the model
Configuration Types
Types for configuring API requests:- GenerateContentConfig - Content generation parameters
- HttpOptions - HTTP request options
- HttpRetryOptions - Retry configuration
Enum Types
The module includes many enum types for API options:Type Hierarchy
Common Patterns
Creating Content
Using Configuration
See Also
- Content Types - Detailed content type reference
- Part Class - Part factory methods
- Configuration Types - Configuration options
- Client Reference - Using types with the client