Pydantic AI
Pydantic AI is a typed Python AI SDK for building agents with structured outputs, tools, and multi-model support. It solves the problem of untyped, vendor-locked AI integrations by providing a single API for many models and interfaces. It is for Python developers who want to build reliable, type-checked AI applications.
✨ Key features
- Typed end-to-end: structured outputs, typed tools, and dependency injection.
- Model-agnostic: swap models via string, supports many providers.
- Capabilities: reusable bundles of tools, instructions, and hooks.
- Durable execution: first-party integrations with Temporal, DBOS, Prefect.
- Multiple interfaces: CLI, web, realtime voice, and more.
- OpenTelemetry-native instrumentation for monitoring and tracing.
🎯 Use cases
- Build a coding agent that runs in the terminal with file and shell access.
- Extract structured data from text with guaranteed output types.
- Create durable background workflows that survive restarts.
- Implement realtime voice assistants with tool calling.
- Generate images as typed outputs from an agent.
📦 Installation
🧰 Requirements: Python 3.9+ (inferred from typical Pydantic projects) and an API key for the chosen model provider (e.g., OpenAI, Anthropic).
uv add pydantic-ai
For additional features, add extras like pydantic-ai[temporal] or pydantic-ai[openai-realtime].
🚀 Usage
from pydantic_ai import Agent
agent = Agent('openai:gpt-5.6-sol')
result = agent.run_sync('Hello')
print(result.output)
❓ FAQ
Which models are supported?
Virtually every model and provider, including OpenAI, Anthropic, Google, Bedrock, Azure AI Foundry, Groq, Mistral, xAI, Ollama, and dozens more, swappable with a string.
How do I get structured output?
Define a Pydantic model and pass it as output_type to the Agent. The run will return a validated instance of that model.
Can I use the same agent in different interfaces?
Yes, one agent definition can run as a CLI, a web chat, realtime voice, or as a plain object you call run() on.
How do I add tools?
Use the @agent.tool decorator on a function. The function's signature and docstring become the tool schema, and arguments are validated before execution.
📊 Repository
🤖 Overview, features, install steps and FAQ were generated from the project's README on Sep 4, 2026. Always check the original source before running commands.