Overview - Pydantic2
Description: A powerful Python framework for building AI applications with structured responses powered by Pydantic AI

Skip to content

# Usage and Cost Management

Pydantic2 provides comprehensive usage tracking and cost management capabilities through two main components:

## Overview

1. Model Pricing
2. Model price management
3. Budget control
4. Cost calculation

5. Price updates

6. Request Tracking

7. Request lifecycle
8. Usage monitoring
9. Performance tracking
10. Usage analysis

## Quick Links

- Model Pricing Documentation
- Request Tracking Documentation
- CLI Tools

## Basic Example

    from pydantic2 import PydanticAIClient

    # Initialize client with usage tracking
    client = PydanticAIClient(
        model_name="openai/gpt-4",
        client_id="my_app",
        user_id="user123",
        max_budget=10.0  # Optional budget limit
    )

    # Make API calls...
    response = client.generate(...)

    # Get usage statistics
    stats = client.get_usage_stats()
    print(f"Total cost: ${stats['total_cost']:.4f}")

Detailed Documentation

See Model Pricing and Request Tracking for detailed information about each component.

March 18, 2025 12:38:18