Pydantic AIPydantic AI 2.51 · Python 3.10+
Dashboard
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
29 small wins to finish your pathNext lesson →

Installation and setup

Pydantic AI installs as a slim core plus one extra for each model provider you want.

Last updated: 28 Sep, 2026 · Pydantic AI 2.51

pydantic-ai-slim is the framework without any provider libraries. An extra such as [openai] adds one provider's client. The full pydantic-ai package pulls in every provider at once.

Installing the slim core and extras

[openai] adds OpenAI's client and [mcp] the MCP client used later. pydantic-evals and pytest are for the testing part.

pip install "pydantic-ai-slim[openai,mcp]==2.51.0" "pydantic-evals==2.51.0" pytest

Checking the installed version

Print the version so the rest of the course matches what you have:

Example
from importlib.metadata import version

print(version("pydantic-ai-slim"))

The number you see is the version every output in this course was captured against.

What each package does

Adding a provider and its keyOptional

From Real models: providers, keys and model names an agent can run on a hosted model. Add the provider's extra, set its key in the environment, then name the model when you create the agent:

python
from pydantic_ai import Agent

agent = Agent("groq:openai/gpt-oss-120b", instructions="You answer support tickets.")
ProviderWhere the key is madeVariableExtra and model string
Groqconsole.groq.com/keysGROQ_API_KEY[groq], "groq:openai/gpt-oss-120b"
Geminiaistudio.google.com/apikeyGOOGLE_API_KEY[google], "google:gemini-2.5-flash"
OpenAIplatform.openai.com/api-keysOPENAI_API_KEY[openai], "openai:gpt-4.1"
pip install "pydantic-ai-slim[groq]==2.51.0"
export GROQ_API_KEY=gsk_...
Watch out. With no key set for its provider, naming a hosted model raises a UserError as soon as you create the agent, before any run. Set the key first, or stay on the test model until Real models: providers, keys and model names.
Try it yourself
  • Run the version check. Does your number match the one shown?
  • Import from pydantic_ai import Agent and confirm no error.
  • Create Agent("groq:openai/gpt-oss-120b") with no key set and read the error.

Little by little, you're building something great.