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

Skip to content

# Installation

## Requirements

- Python 3.8 or higher
- OpenRouter API key (for model access)
- Internet connection (for online search feature)

## Installing Pydantic2

### Using pip

    pip install pydantic2

### From source

    git clone https://github.com/markolofsen/pydantic2.git
    cd pydantic2
    pip install -e .

## API Key Setup

Pydantic2 uses OpenRouter as its default model provider. You'll need to set up your API key:

### Environment Variable

    export OPENROUTER_API_KEY=your_api_key_here

### In your code

    from pydantic2 import PydanticAIClient

    client = PydanticAIClient(
        api_key="your_api_key_here"
    )

## Verifying Installation

Create a test script to verify your installation:

    from pydantic2 import PydanticAIClient
    from pydantic import BaseModel, Field

    class TestResponse(BaseModel):
        message: str = Field(description="Test message")

    client = PydanticAIClient(verbose=True)

    # Add a simple test message
    client.message_handler.add_message_user("Hello, world!")

    # Generate response
    response: TestResponse = client.generate(result_type=TestResponse)
    print(response.message)

## Optional Dependencies

### For async support

    pip install aiohttp

### For colored logging

    pip install colorlog

### For development

    pip install -e ".[dev]"

## Troubleshooting

### Common Issues

1. API Key Not Found

       # Set API key in code
       client = PydanticAIClient(api_key="your_api_key")

2. Model Not Found

       # Specify full model name
       client = PydanticAIClient(
           model_name="openai/gpt-4o-mini"
       )

3. Budget Errors

       # Set appropriate budget
       client = PydanticAIClient(max_budget=10.0)

### Getting Help

- Check our GitHub Issues
- Email support: support@unrealos.com

## Next Steps

- Quick Start Guide
- Configuration Guide
- Basic Usage Examples

March 17, 2025 18:11:48