subagentic.ai RSS X YouTube GitHub
AI-generated illustration

How-Tos

How to install Pydantic AI

Install Pydantic AI with pip or uv on Python 3.11+, including default model libraries, slim extras, and the installation page's handoff to the Agents guide.

pydantic-aipythonagents

Pydantic AI is published on PyPI as pydantic-ai, and the official installation page treats setup as a one-line step. After that, it sends you to the Agents guide to build the first agent. This is the install path that page actually documents: Python 3.11 or newer, the default package, slim extras, the examples group, TLS, and the handoff it names.

Check Python, then install

Requires Python 3.11+. The install provides the pydantic_ai package. The project name you pass to the installer is pydantic-ai.

The page shows pip and uv:

pip install pydantic-ai
uv add pydantic-ai

That install includes the pydantic_ai package, core dependencies, and the libraries required to use the OpenAI, Anthropic, and Google models. It also includes the CLI, MCP, Evals, Web UI, and Logfire integrations listed on the page.

If the first agent will use OpenAI, Anthropic, or Google, stop here. Those three are already in the default install. Extras are for everything else, or for a smaller install.

Extras and the slim package

To use any other models or integrations, add the relevant extras to the install command, for example pydantic-ai[bedrock,temporal].

The alternative is pydantic-ai-slim, for when you know the model and want to avoid superfluous packages. If you are using just OpenAIChatModel, the page shows:

pip install "pydantic-ai-slim[openai]"
uv add "pydantic-ai-slim[openai]"

You can install dependencies for multiple models and use cases. The page's combined example is:

pip install "pydantic-ai-slim[openai,google,logfire]"
uv add "pydantic-ai-slim[openai,google,logfire]"

pydantic-ai-slim optional groups named on the installation page:

  • logfire installs the Logfire dependency logfire
  • evals installs pydantic-evals
  • openai installs openai
  • google installs google-genai
  • anthropic installs anthropic
  • groq installs groq
  • mistral installs mistralai
  • cohere installs cohere
  • bedrock installs boto3
  • bedrock-mantle installs openai and botocore
  • xai installs xai-sdk
  • openrouter, zai, snowflake, crusoe, and cerebras each install openai
  • typesafe installs typesafe-sdk
  • huggingface installs huggingface-hub
  • sentence-transformers installs sentence-transformers
  • voyageai installs voyageai
  • duckduckgo installs ddgs
  • tavily installs tavily-python
  • exa installs exa-py
  • web-fetch installs markdownify
  • cli installs rich, prompt-toolkit, and argcomplete
  • mcp installs fastmcp-slim[client]
  • mcp-tasks installs fastmcp-tasks
  • ui installs starlette
  • web installs starlette and uvicorn
  • ag-ui installs ag-ui-protocol and starlette
  • retries installs tenacity, plus legacy httpx support until Pydantic AI v3
  • temporal installs temporalio
  • dbos installs dbos
  • prefect installs prefect
  • spec installs pyyaml and pydantic-handlebars

Use a group from that list. A provider extra that is not named on the page is not documented here.

The page also describes what several of those groups are for, beyond the package name. sentence-transformers and voyageai are embedding models. duckduckgo, tavily, exa, and web-fetch are search or fetch tools. temporal, dbos, and prefect are durable-execution integrations. spec is AgentSpec. You do not need those groups for a default OpenAI, Anthropic, or Google install.

Optional examples package

Examples are distributed as a separate PyPI package, pydantic-ai-examples, from the pydantic_ai_examples directory, so they are easy to customize and run. Install them with the examples optional group:

pip install "pydantic-ai[examples]"
uv add "pydantic-ai[examples]"

To run them, the page says to follow the examples docs. Those run instructions are not on the installation page, so they are not repeated here.

TLS certificates

Pydantic AI's own HTTP requests, and those of providers migrated to httpx2, verify TLS certificates against the operating system trust store rather than shipping a certifi bundle. Minimal container images and corporate proxies that rely on a private CA need those certificates installed in the image. The page's example is the ca-certificates package, plus your proxy's root CA.

Alternatively, pass such a provider an httpx2.AsyncClient you configured yourself through its http_client argument. The page says to see the provider docs for the client each one accepts. Providers whose SDKs still use legacy httpx, such as Groq and Cohere, keep its certifi-based verification and take a legacy httpx.AsyncClient instead.

The page's next step

Once the package is installed, the page's next step is to build your first agent with the Agents guide, or start from one of the examples. It repeats that at the end: with Pydantic AI installed, build your first agent with the Agents guide.

The same next-steps section names a few related moves:

  • To see what your agent does, run uvx logfire-cli wizard --task pydantic-ai once to set up Pydantic Logfire. The page says Logfire has a free tier, no credit card, and sign up with a GitHub account. It also says you can use Logfire for local development even if your team uses another tool in production.
  • To reach models from several providers with one API key, use the Pydantic AI Gateway.
  • If a coding agent is building with you, install the Pydantic AI skill.
  • When you are ready to deploy, read Going to Production.

What to do next

On Python 3.11 or newer, run pip install pydantic-ai or uv add pydantic-ai. Switch to pydantic-ai-slim only when you already know which optional group you need. Then open the Agents guide named on the installation page and build the first agent from that guide. If you would rather start from a shipped example, install the examples extra with the quoted commands above and follow the examples docs. Run uvx logfire-cli wizard --task pydantic-ai once to set up Logfire so you can see what the agent does.

Sources