Setting Up Claude Agent SDK
This lesson gets you from nothing to a working agent in about 20 minutes. If you have Python and an Anthropic API key, you are almost there already.
What You Need
Python 3.10 or newer. Check yours with python --version in a terminal. If you get anything older than 3.10, install a newer version from python.org.
A code editor. VS Code, Cursor, PyCharm or any other Python editor works.
An Anthropic API key. Sign up at console.anthropic.com. The free tier gives you enough credit to work through this whole module. Keep the key private. Never commit it to git.
A terminal. Whatever your operating system uses. Windows Terminal, Terminal.app or GNOME Terminal all work fine.
Step 1: Create a Project Folder
Open a terminal. Make a folder for this course and step into it:
mkdir hardcoded-agents
cd hardcoded-agents
Step 2: Create a Virtual Environment
Python virtual environments keep your project's dependencies isolated from the rest of your system. Do this once per project:
python -m venv .venv
Activate it. On macOS or Linux:
source .venv/bin/activate
On Windows PowerShell:
.venv\Scripts\Activate.ps1
You should see (.venv) appear at the start of your terminal prompt. That means the environment is active. Any pip install you run from now on installs into this folder, not your system Python.
Step 3: Install the SDK
pip install anthropic
That single install pulls in the Anthropic Python SDK, which includes the agent-building tools we need. No separate agent SDK install is required.
Step 4: Set Your API Key
Create a file called .env in your project folder. Add one line:
ANTHROPIC_API_KEY=sk-ant-...
Replace the placeholder with your actual key from the Anthropic console. Also install python-dotenv so we can read this file:
pip install python-dotenv
Add a .gitignore file that includes .env and .venv so you never accidentally commit either. This is important. A leaked API key is a real security problem.
Step 5: Write Your First Agent
Create first_agent.py:
import anthropic
from dotenv import load_dotenv
load_dotenv()
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-sonnet-4-5",
max_tokens=1024,
messages=[
{"role": "user", "content": "In one paragraph, describe what an AI agent is."}
]
)
print(response.content[0].text)
Run it:
python first_agent.py
If you see a paragraph of text explaining agents, everything is working. If you see an authentication error, double-check your API key. If you see an import error, check that the virtual environment is active.
What Just Happened
You made a single API call to Claude with no tools defined. That is not yet an agent (no loop, no tools). It is a warm-up to confirm the plumbing works. The next lesson builds the actual loop.
Common Setup Problems
"ANTHROPIC_API_KEY not set." The client did not find your key. Check that load_dotenv() runs before you create the client, and that your .env file is in the same folder you ran the script from.
"Model not found." Model names change. Check the Anthropic docs for the current recommended Sonnet model. claude-sonnet-4-5 is current as of mid-2026.
"Rate limit exceeded." The free tier has strict per-minute limits. Wait a minute and try again. For heavy development work, add a payment method to your Anthropic account for higher limits.
Key Takeaway
The Claude Agent SDK is the Python anthropic package plus a few conventions. If you have Python 3.10, a virtual environment, an API key and pip install anthropic, you are ready to build an agent. The next lesson turns this one-shot call into a proper agent loop with tools.