Skip to main content

Overview

The types 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:
Benefits:
  • Runtime validation
  • Type safety
  • Helper methods and constructors
  • Serialization/deserialization

TypedDict

TypedDict definitions provide type hints for dictionaries:
Benefits:
  • 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:

Enum Types

The module includes many enum types for API options:
All enums are case-insensitive:

Type Hierarchy

Common Patterns

Creating Content

Using Configuration

See Also