The Complete Guide to the Anthropic Cookbook: Building with Claude AI
Learn how to use the Anthropic Cookbook to build Claude AI applications. Covers setup, code style, model selection, project structure, and best practices for developers.
This guide walks you through the Anthropic Cookbook repository—a collection of Jupyter notebooks and Python examples for building with the Claude API. You'll learn setup, code style, model selection, project structure, and how to contribute your own cookbook.
The Complete Guide to the Anthropic Cookbook: Building with Claude AI
If you're building applications with Claude AI, the Anthropic Cookbook is your essential resource. This official repository contains a curated collection of Jupyter notebooks and Python examples that demonstrate everything from basic API calls to advanced patterns like tool use, multimodal processing, and extended reasoning.
In this guide, I'll walk you through everything you need to know to get started with the Cookbook, follow best practices, and even contribute your own examples.
What Is the Anthropic Cookbook?
The Cookbook is Anthropic's official repository of practical, runnable examples for the Claude API. It's designed for developers who want to move beyond the API documentation and see real-world implementations of Claude's capabilities.
Whether you're building a RAG system, implementing classification pipelines, or experimenting with Claude's vision features, the Cookbook provides battle-tested templates you can adapt for your own projects.
Getting Started: Setup and Installation
Prerequisites
Before diving in, make sure you have:
- Python 3.10+ installed
- An Anthropic API key (get one at console.anthropic.com)
- Basic familiarity with Python and Jupyter notebooks
Step 1: Clone the Repository
git clone https://github.com/anthropics/anthropic-cookbook.git
cd anthropic-cookbook
Step 2: Install Dependencies
The Cookbook uses uv for dependency management—a fast Python package installer. Install all dependencies with:
uv sync --all-extras
This single command installs everything you need, including Jupyter, the Anthropic SDK, and all third-party integrations.
Step 3: Configure Your API Key
cp .env.example .env
Then edit the .env file and add your ANTHROPIC_API_KEY. Never commit this file—the .gitignore is already configured to exclude it.
Step 4: Install Pre-commit Hooks (Optional but Recommended)
uv run pre-commit install
This ensures your code meets the project's quality standards before every commit.
Understanding the Code Style
The Cookbook enforces a consistent code style to keep examples clean and readable:
| Rule | Standard |
|---|---|
| Line length | 100 characters |
| Quotes | Double quotes (") |
| Formatter | Ruff (replaces Black) |
| Linter | Ruff |
- E402: Mid-file imports are allowed (common in notebooks)
- F811: Redefinitions are permitted
- N803/N806: Variable naming conventions are looser
Running Quality Checks
Before submitting any changes, run the full quality check suite:
make check
Or use uv directly:
uv run ruff format .
uv run ruff check .
Choosing the Right Claude Model
One of the most common mistakes developers make is using dated model IDs. The Cookbook enforces a critical rule: always use non-dated model aliases.
Correct Model IDs
| Model | API Model ID | Bedrock Model ID |
|---|---|---|
| Claude Opus 4.6 | claude-opus-4-6 | global.anthropic.claude-opus-4-6-v1 |
| Claude Sonnet 4.6 | claude-sonnet-4-6 | global.anthropic.claude-sonnet-4-6-v1 |
| Claude Haiku 4.5 | claude-haiku-4-5 | global.anthropic.claude-haiku-4-5-v1 |
claude-sonnet-4-6-20250514. The non-dated aliases always point to the latest stable version of that model.
For Bedrock users, prepend global. for global endpoints (recommended for better availability). Note that models before Opus 4.6 may require dated IDs in their Bedrock model ID.
Example: Making an API Call
import anthropic
from dotenv import load_dotenv
import os
load_dotenv()
client = anthropic.Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY"))
response = client.messages.create(
model="claude-sonnet-4-6", # Always use non-dated alias
max_tokens=1024,
messages=[
{"role": "user", "content": "Explain the Cookbook in one sentence."}
]
)
print(response.content[0].text)
Navigating the Project Structure
The Cookbook is organized into clear directories, each serving a specific purpose:
anthropic-cookbook/
├── capabilities/ # Core Claude capabilities (RAG, classification, etc.)
├── skills/ # Advanced skill-based notebooks
├── tool_use/ # Tool use and integration patterns
├── multimodal/ # Vision and image processing
├── misc/ # Batch processing, caching, utilities
├── third_party/ # Pinecone, Voyage, Wikipedia integrations
├── extended_thinking/ # Extended reasoning patterns
├── scripts/ # Validation scripts
└── .claude/ # Claude Code commands and skills
Key Directories Explained
- capabilities/: Start here if you're new to Claude. Contains notebooks for RAG, text classification, summarization, and more.
- tool_use/: Demonstrates how to give Claude access to external tools and APIs.
- multimodal/: Shows how to work with images, PDFs, and other non-text inputs.
- extended_thinking/: Explores Claude's extended reasoning capabilities for complex problem-solving.
- third_party/: Integrations with vector databases (Pinecone), embedding providers (Voyage), and knowledge sources (Wikipedia).
Using Slash Commands
The Cookbook integrates with Claude Code through slash commands that automate common tasks:
/notebook-review— Reviews notebook quality and structure/model-check— Validates that all Claude model references use correct, non-dated IDs/link-review— Checks links in changed files for validity
How to Contribute a New Cookbook
Contributing your own example is straightforward. Here's the process:
Step 1: Create Your Notebook
Place your notebook in the appropriate directory based on its content. Follow these guidelines:
- One concept per notebook — Don't cram multiple ideas into one file
- Keep outputs — Unlike typical notebooks, outputs should be preserved for demonstration
- Test top-to-bottom — Ensure the notebook runs without errors when executed sequentially
Step 2: Register Your Notebook
Add an entry to registry.yaml:
- title: "Your Notebook Title"
description: "Brief description of what this notebook demonstrates"
path: capabilities/your-notebook.ipynb
authors:
- your-github-username
categories:
- capabilities
Step 3: Add Author Info
If you're a new contributor, add your details to authors.yaml:
your-github-username:
name: Your Full Name
url: https://github.com/your-github-username
Step 4: Run Quality Checks
make check
Fix any issues, then submit your PR.
Best Practices for Working with the Cookbook
1. Always Use Environment Variables
Never hardcode API keys. The Cookbook uses python-dotenv for this:
from dotenv import load_dotenv
import os
load_dotenv()
api_key = os.getenv("ANTHROPIC_API_KEY") # Never os.environ["KEY"]
2. Manage Dependencies with uv
Add new dependencies using uv add, never by editing pyproject.toml directly:
uv add requests # Production dependency
uv add --dev pytest # Development dependency
3. Follow Conventional Commits
When committing changes, use the conventional commit format:
feat(capabilities): add RAG notebook with Pinecone
fix(tool_use): correct API endpoint in weather example
docs: update README with new directory structure
style: format notebooks with ruff
4. Use Proper Branch Names
Name your branches with your username and a feature description:
git checkout -b yourname/add-rag-example
Real-World Example: Building a Simple RAG System
Let's look at a practical example you might find in the capabilities/ directory. Here's a simplified version of a RAG (Retrieval-Augmented Generation) notebook:
import anthropic
from dotenv import load_dotenv
import os
load_dotenv()
client = anthropic.Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY"))
Simulated retrieved context
context = """
Claude Opus 4.6 is Anthropic's most powerful model, excelling at complex reasoning,
creative writing, and nuanced analysis. It has a 200K token context window.
"""
user_query = "What is the context window of Claude Opus 4.6?"
response = client.messages.create(
model="claude-opus-4-6",
max_tokens=1024,
system="You are a helpful assistant. Answer questions based on the provided context.",
messages=[
{
"role": "user",
"content": f"Context: {context}\n\nQuestion: {user_query}"
}
]
)
print(response.content[0].text)
Output: Claude Opus 4.6 has a 200K token context window.
This pattern—retrieve context, then generate with Claude—is the foundation of many production RAG systems.
Key Takeaways
- The Anthropic Cookbook is your hands-on resource for learning Claude API patterns through practical, runnable Jupyter notebooks organized by capability.
- Always use non-dated model aliases (e.g.,
claude-sonnet-4-6) to ensure your code always points to the latest stable version of each model. - Follow the project's code style and quality checks—use Ruff for formatting/linting, conventional commits, and run
make checkbefore submitting changes. - Contribute your own examples by creating a focused notebook, registering it in
registry.yaml, and following the PR workflow with proper branch naming. - Leverage slash commands like
/notebook-reviewand/model-checkto automate quality assurance in both Claude Code and CI pipelines.