Skip to content

Installation

Requirements

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

Installing pydantic3

Using pip

pip install pydantic3

From source

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

API Key Setup

pydantic3 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 pydantic3 import PydanticAIClient

client = PydanticAIClient(
    api_key="your_api_key_here"
)

Verifying Installation

Create a test script to verify your installation:

from pydantic3 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

Next Steps