Skip to content

Repository files navigation

Building with the Claude API

This repository contains hands-on exercises and examples from the Anthropic course: Building with the Claude API.

Modules

Module 1: Accessing Claude with the API

📁 001-Accessing-Claude_with-the-API/

Learn the fundamentals of interacting with Claude through the Anthropic API.

Notebook Description
001_requests.ipynb Basic API requests, message handling, and multi-turn conversations
001_requests_exercise.ipynb Build an interactive chatbot using the messages API
002_system_prompt.ipynb Using system prompts to guide Claude's behavior
002_system_prompt_exercise.ipynb Create a concise Python code assistant with system prompts
003_temperature.ipynb Controlling output randomness with the temperature parameter
004_streaming.ipynb Real-time response streaming and handling stream events
005_controlling_output.ipynb Message prefilling, stop sequences, and structured output (JSON)

Module 2: Prompt Evaluation

📁 002-Prompt-evaluation/

Learn how to systematically evaluate and grade prompt outputs using datasets, model-based grading, and code-based validation.

Notebook Description
001_generating_dataset.ipynb Generate evaluation datasets for testing prompts
002_running_eval.ipynb Run evaluations across test cases and collect results
003_model_based_grading.ipynb Use Claude to grade and evaluate AI-generated solutions
004_code_based_grading.ipynb Combine syntax validation (JSON, Python, Regex) with model grading
005_exercise.ipynb Exercise: Enhance the model grader with solution criteria

Module 3: Prompt Engineering Techniques

📁 003-Prompt-engineering/

Master essential prompt engineering techniques to improve Claude's output quality, consistency, and accuracy.

Notebook Description
001_prompting.ipynb Introduction to prompt engineering with the PromptEvaluator framework
002_being_clear_direct.ipynb Writing clear and direct prompts for better results
003_being_specific.ipynb Using guidelines and step-by-step instructions for complex tasks
004_xml.ipynb Structuring prompts with XML tags for clarity and organization
005_providing_examples.ipynb One-shot and multi-shot examples to guide model behavior
006_prompting_exercise.ipynb Exercise: Extract topics from scholarly articles

Module 4: Tool Use with Claude

📁 004-Tool-use-with-Claude/

Learn how to extend Claude's capabilities by defining tools, handling tool calls, and building multi-turn agentic workflows.

Notebook Description
001_tools_function.ipynb Introduction to tool functions for accessing real-time information
002_tools_schemas.ipynb Creating JSON schemas to define tool arguments
003_tools_handling_message_blocks.ipynb Handling multi-block messages with text and tool use content
004_tools_sending_tool_results.ipynb Executing functions and sending results back to Claude
005_tools_multi-turn-conversations.ipynb Calling multiple tools in sequence to answer a single question
006_tools_implementing_multiple_turns.ipynb Building a conversation loop that runs until tool use completes
007_tools_using_multiple_tools.ipynb Integrating multiple tools into a single implementation
008_tools_batch_tools.ipynb Running multiple tool calls in parallel within a single message
009_tools_structured_data.ipynb Using tools to extract structured data reliably
010_tools_fine_grained_tool_calling.ipynb Combining tool use with streaming for real-time updates
011_tools_text_edit.ipynb Using Claude's built-in text editor tool for file operations
012_tools_web_search.ipynb Enabling Claude's built-in web search tool for current information

Module 5: Retrieval-Augmented Generation (RAG)

📁 005-Retrieval-Augmented-Generation/

Build RAG pipelines from scratch, covering chunking strategies, embeddings, vector search, lexical search, and advanced retrieval techniques.

Additional setup required for this module:

  • Install the Voyage AI package: pip install voyageai
  • Add your Voyage AI API key to .env: VOYAGE_API_KEY="your_key_here" (Get one here)
Notebook Description
001_introducing-RAG.ipynb Text chunking strategies: size-based, structure-based, and semantic-based
002_embeddings.ipynb Generating text embeddings for semantic search over document chunks
003_vectordb.ipynb Complete RAG flow with chunking, embeddings, vector storage, and similarity search
004_bm25.ipynb BM25 lexical search as a complement to semantic search
005_hybrid.ipynb Hybrid search combining semantic and lexical retrieval with Reciprocal Rank Fusion
006_reranking.ipynb Reranking retrieved documents with Claude for improved accuracy
007_contextual.ipynb Contextual retrieval to preserve document context in chunked passages

Module 6: Features of Claude

📁 006-Feature-of-Claude/

Explore Claude's advanced built-in features including extended thinking, vision, PDF processing, citations, caching, and code execution.

Notebook Description
001_thinking.ipynb Extended thinking for complex reasoning before generating responses
002_images.ipynb Vision capabilities for analyzing and understanding images
003_pdf.ipynb Reading and analyzing PDF files for document processing
004_citations.ipynb Citations to trace answers back to specific source locations
005_caching.ipynb Prompt caching to speed up responses and reduce costs
006_code_execution.ipynb Files API and code execution for delegating complex tasks

Module 7: Model Context Protocol (MCP)

📁 007-Model-Context-Protocol/

Learn how to build MCP servers and clients to extend Claude with tools, resources, and reusable prompts through a standardized protocol.

Additional setup required for this module:

  • Install uv (recommended): curl -LsSf https://astral.sh/uv/install.sh | sh
  • Run uv sync inside the cli_project directory to install dependencies
  • Add CLAUDE_MODEL to the project's .env file (e.g., CLAUDE_MODEL="claude-sonnet-4-5")
File Description
NOTES.md Concise reference notes on MCP concepts and the sample project
cli_project/mcp_server.py MCP server defining tools, resources, and prompts using FastMCP
cli_project/mcp_client.py MCP client connecting to servers via stdio transport
cli_project/main.py Entry point wiring the MCP client with an interactive CLI chat
cli_project/core/chat.py Multi-turn tool execution loop with Claude
cli_project/core/cli_chat.py CLI chat with @ document mentions and / command prompts
cli_project/core/tools.py Tool discovery and execution across multiple MCP clients
cli_project/core/cli.py Interactive CLI with tab-completion and auto-suggest

Module 8: Anthropic Apps

📁 008-Anthropic-Apps/

Explore two powerful Anthropic applications — Claude Code and Computer Use — and build a real MCP document tools server using the included app_starter project.

Additional setup required for this module (app_starter/):

  • Install uv if not already installed: curl -LsSf https://astral.sh/uv/install.sh | sh
  • cd 008-Anthropic-Apps/app_starter
  • uv venv && source .venv/bin/activate
  • uv pip install -e .
  • Run the MCP server: uv run main.py
  • Run tests: uv run pytest
File Description
NOTES.md Notes on Claude Code, Computer Use, /init, and MCP server registration
app_starter/main.py FastMCP server entry point registering document and math tools
app_starter/tools/document.py Tool to convert PDF/DOCX files to Markdown via MarkItDown
app_starter/tools/math.py Reference tool implementation demonstrating the expected tool definition pattern
app_starter/tests/test_document.py pytest tests for the document conversion tool

Module 9: Agents and Workflows

📁 009-Agents-and-workflows/

Learn the core strategies for building multi-step AI systems — chaining, routing, parallelization workflows — and fully autonomous agents powered by tools.

File Description
NOTES.md Concise reference notes on workflows, agents, and when to use each strategy

Setup

Prerequisites

Installation

  1. Clone the repository:

    git clone https://github.com/jaygaha/Building-with-the-Claude-API.git
    cd Building-with-the-Claude-API
  2. Create and activate a virtual environment:

    python -m venv .venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  3. Install dependencies:

    pip install -r requirements.txt
  4. Configure your API key:

    cp .env-example .env

    Then edit .env and add your Anthropic API key.

  5. Launch Jupyter:

    jupyter notebook

Resources

About

Anthropic course: Building with the Claude API

Topics

Resources

Stars

9 stars

Watchers

0 watching

Forks

Contributors

Languages