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" pytestChecking the installed version
Print the version so the rest of the course matches what you have:
from importlib.metadata import version
print(version("pydantic-ai-slim"))2.51.0
The number you see is the version every output in this course was captured against.
What each package does
pydantic-ai-slimis the framework: agents, tools, output types, retries.[openai],[groq],[google]and other extras each add one provider's client.- Nothing here needs an API key. Lessons up to Real models: providers, keys and model names run on the built-in test model and the function model you write in FunctionModel: write a stand-in model.
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:
from pydantic_ai import Agent
agent = Agent("groq:openai/gpt-oss-120b", instructions="You answer support tickets.")| Provider | Where the key is made | Variable | Extra and model string |
|---|---|---|---|
| Groq | console.groq.com/keys | GROQ_API_KEY | [groq], "groq:openai/gpt-oss-120b" |
| Gemini | aistudio.google.com/apikey | GOOGLE_API_KEY | [google], "google:gemini-2.5-flash" |
| OpenAI | platform.openai.com/api-keys | OPENAI_API_KEY | [openai], "openai:gpt-4.1" |
pip install "pydantic-ai-slim[groq]==2.51.0"export GROQ_API_KEY=gsk_...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.Related
- Previous: Pydantic AI overview
- Next: Agent basics and a first run
- Reference: Install Pydantic AI
- Run the version check. Does your number match the one shown?
- Import
from pydantic_ai import Agentand 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.