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

Installation and setup

Pydantic AI installs as a slim core plus one extra per model provider. Groq and Gemini each have an extra and a free key.

pydantic-ai-slim[openai], pydantic-evals and pytest

pydantic-ai-slim is the framework without provider libraries; [openai] adds OpenAI's. The full pydantic-ai package installs every provider at once. pydantic-evals is for lesson 22 and pytest for lesson 21.

pip install "pydantic-ai-slim[openai]==2.43.0" "pydantic-evals==2.43.0" pytest
Example
from importlib.metadata import version

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

Provider extras and model stringsOptional

The course runs on the built-in test model and a function model you write in lesson 4, so it needs no key. Lesson 6 moves to real providers: add the provider's extra, set its key and name the model.

python
from pydantic_ai import Agent

agent = Agent("groq:openai/gpt-oss-120b", instructions="You answer support tickets.")
ProviderKeyVariableExtra and model string
GroqFree, console.groq.com/keysGROQ_API_KEY[groq], "groq:openai/gpt-oss-120b"
GeminiFree, aistudio.google.com/apikeyGOOGLE_API_KEY[google], "google:gemini-2.5-flash"
OpenRouterFree models end in :free, openrouter.ai/keysOPENROUTER_API_KEY[openrouter], "openrouter:google/gemma-4-31b-it:free"
OpenAIPaid, platform.openai.com/api-keysOPENAI_API_KEY[openai], "openai:gpt-5.2"
pip install "pydantic-ai-slim[groq]==2.43.0"
export GROQ_API_KEY=gsk_...
Try it yourself
  • Create the agent above with no key set and read the error message.

Little by little, you're building something great.