Anthropic Cookbook: 10 Code Examples From the Official Repo

AI Assistant Summary: The Anthropic Cookbook is the official GitHub repository of working Jupyter notebooks for building with Claude. It’s free, open-source, and the fastest way to learn by copying real examples. The repo is organized into ~15 categories: capabilities, tool_use, multimodal, agents, evaluation, finetuning, observability, and more. This guide curates the 10 most useful notebooks for beginners and intermediate builders: vision basics, customer service agents with tool use, retrieval-augmented generation with Pinecone, PDF summarization, prompt caching for cost optimization, Wikipedia search integration, sub-agent patterns, SQL query generation, web page extraction, and chart reading. Every notebook is a working starting point you can clone and modify.

The Anthropic Cookbook is one of the most underused free resources for Claude developers. It’s a GitHub repository of real, working code — not stub documentation — that shows exactly how to build common patterns with the Claude API. Every notebook is a Jupyter file you can clone, open in Colab or VS Code, and run with your API key. This guide picks 10 notebooks that cover the most useful first patterns to learn.

How to use the Cookbook

  • Browse: Visit github.com/anthropics/anthropic-cookbook in your browser. Each folder corresponds to a topic.
  • Clone: git clone https://github.com/anthropics/anthropic-cookbook.git if you want everything locally.
  • Run a single notebook: Click any .ipynb file, then “Open in Colab” (top of the file). Add your Anthropic API key as an environment variable and run cell-by-cell.
  • Search: GitHub’s built-in search works on file names and content. Looking for “PDF summarization”? Just search the repo for “PDF”.

The 10 notebooks worth your time first

#NotebookCategoryWhat it teaches
1getting_started_with_visionmultimodalPass images to Claude and parse responses
2customer_service_agenttool_useBuild a working agent with tool calls
3rag_using_pineconetool_use / third_partyRetrieval-augmented generation with vector DB
4pdf_upload_summarizationcapabilitiesParse and summarize PDF documents
5prompt_cachingcapabilitiesCut API costs 50-90% with cached context
6wikipedia-search-cookbooktool_useGive Claude real-time knowledge access
7read_web_pages_with_haikucapabilitiesFetch and process web content cheaply
8using_sub_agentspatterns/agentsUse Haiku as a sub-agent for Opus or Sonnet
9how_to_make_sql_queriestool_useGenerate and execute database queries
10reading_charts_graphs_powerpointsmultimodalExtract data from charts and presentations

1-on-1 Coaching

Claude AI Crash Course

1-hour private video session with James. Walk through which cookbook notebook applies to your project, run it against your actual data, and leave with a working Claude integration. No technical background required — we’ll handle the code together.

$75

1-hour live

Book session →

Group Format

AI Workshops for Teams

Team-format workshops for businesses rolling Claude out to staff. We walk your team through cookbook examples that match your stack and build a shared template library. Best for 3+ people.

Custom

pricing

Get a quote →

1. getting_started_with_vision

Category: multimodal · Difficulty: beginner

The starter notebook for anyone working with images in Claude. Walks through encoding images as base64, sending them to the Messages API, and parsing the response. Includes examples with screenshots, photos, document scans, and diagrams.

Why start here: Vision is one of the most useful Claude capabilities and is often the first “wow” moment for developers who started with text. Once you can send an image and get a structured answer back, the use cases multiply quickly: receipt OCR, chart reading, screenshot analysis, scanned document processing.

2. customer_service_agent

Category: tool_use · Difficulty: intermediate

The reference example for building an agent. Claude is given tools (lookup_order, get_customer_info, issue_refund) and a system prompt defining a support persona. Users send queries; Claude decides whether to answer directly or call a tool; the notebook shows the entire tool-call/tool-result loop in working code.

Why it matters: Every customer-facing Claude integration eventually wants to call your APIs (CRM, ticketing, payment processor, etc.). This notebook is the cleanest pattern for it. Copy the tool-call loop, swap in your own tool definitions, and you have a working agent in an hour. The official tool use documentation goes deeper.

3. rag_using_pinecone

Category: tool_use / third_party · Difficulty: intermediate

Retrieval-augmented generation (RAG) is how you give Claude knowledge of your specific documents. This notebook uses Pinecone as the vector database, Voyage AI for embeddings, and Claude as the generation step. You can swap Pinecone for any vector DB (Weaviate, Qdrant, Chroma) with minimal changes.

Why it matters: RAG is the default pattern for “chat with my docs” applications. Every internal Q&A bot, every company knowledge base assistant, every “chat with a PDF” tool uses some variant of this pattern. This notebook is the canonical Anthropic-blessed reference implementation.

4. pdf_upload_summarization

Category: capabilities · Difficulty: beginner

How to upload a PDF directly to Claude (via the Files API) and get a summary back. Covers extracting structured fields, generating chapter outlines, and pulling specific data points.

Why it matters: PDF processing is one of the most common real-world Claude tasks — reports, contracts, research papers, scanned forms. Claude natively reads PDFs without OCR pre-processing in most cases, which simplifies the pipeline significantly.

5. prompt_caching

Category: capabilities · Difficulty: intermediate

How to mark sections of your prompt as cacheable. Anthropic stores the processed cache for ~5 minutes and charges 10% of the normal input rate on cache hits. The notebook benchmarks a real workload showing 70%+ cost savings when caching is configured correctly.

Why it matters: If you send the same long context (a knowledge base, system prompt, codebase) across many requests, prompt caching is the single biggest cost lever on the entire API. The implementation is a one-line change in most SDKs. Read this notebook before your monthly Claude bill exceeds $100.

6. wikipedia-search-cookbook

Category: tool_use · Difficulty: beginner-intermediate

Gives Claude access to Wikipedia’s API as a tool. Claude can search Wikipedia, read article summaries, and use that information in its answer. Simpler than full RAG — no vector DB needed — but covers a similar “Claude needs current external knowledge” use case.

Why it matters: Demonstrates a low-effort path to adding external knowledge that doesn’t require building infrastructure. Useful for early prototypes, education, and applications where Wikipedia happens to be the right source. Replace the Wikipedia call with your own API (Bloomberg, internal wiki, GitHub) and the pattern transfers directly.

7. read_web_pages_with_haiku

Category: capabilities · Difficulty: beginner

Fetch a web page (with requests, httpx, or a headless browser) and pass the content to Claude Haiku 4.5 for fast extraction. Examples: extracting product details from a page, summarizing an article, pulling structured data from a listing.

Why it matters: Web extraction is a constant production need (price monitoring, news summarization, data scraping). Using Haiku as the LLM keeps costs low at scale — the cost difference between Haiku and Opus on this kind of task is 5x, with minimal quality loss for typical extraction.

8. using_sub_agents

Category: patterns/agents · Difficulty: intermediate-advanced

The pattern where a smart, expensive model (Opus 4.7) orchestrates work and delegates subtasks to faster, cheaper models (Haiku 4.5). The notebook shows a concrete example: Opus plans a research task, Haiku executes the individual sub-queries in parallel, Opus synthesizes the results.

Why it matters: This pattern is how production AI applications stay fast and cheap. The orchestrator model is called sparingly; the worker model is called many times. The math frequently works out to 70-90% cost savings vs. running everything on Opus, with minimal quality drop. Our model comparison post covers when each tier is right.

9. how_to_make_sql_queries

Category: tool_use · Difficulty: intermediate

Gives Claude a database schema and a tool for executing SQL. Users ask in natural language (“show me the top 10 customers by revenue this quarter”); Claude generates the SQL, executes it through the tool, and presents the results in plain English. Includes safety considerations (read-only access, query validation).

Why it matters: Natural-language-to-SQL is one of the highest-leverage internal AI applications. Every business has data analysts spending time writing routine queries that Claude can now generate accurately. The notebook shows the pattern including the often-overlooked safety layer.

10. reading_charts_graphs_powerpoints

Category: multimodal · Difficulty: intermediate

Practical vision applications: extracting numbers from bar charts, reading data from line graphs, parsing PowerPoint slides for structured information. Important nuances around tabular data reading accuracy and when to use vision vs. when to pre-extract to text.

Why it matters: Charts and slides are everywhere in business documents but historically required custom OCR pipelines to parse. Claude does this natively now. The notebook shows the patterns that work and the common pitfalls (low-resolution images, complex multi-series charts).

Other Cookbook sections worth knowing about

  • extended_thinking/ — how to enable and benefit from Claude’s reasoning mode. Worth reading once you understand the basics.
  • finetuning/ — for the rare case where you actually need to fine-tune. Most use cases are better solved with prompting + RAG.
  • managed_agents/ and patterns/agents/ — deeper agent patterns: planning, memory, multi-step coordination.
  • observability/ — logging, evaluation, monitoring — useful when you go to production.
  • tool_evaluation/ — how to systematically test whether Claude’s tool selection is correct on your eval set.
  • misc/ — sundry useful examples that don’t fit other categories. Usually worth a browse.

How the Cookbook fits into a learning path

A practical sequence for someone new to building with Claude:

  1. Read our Anthropic Documentation Guide — the 12 most important docs pages.
  2. Run the official Quickstart — your first API call.
  3. Open the Anthropic Workbench — test prompts visually.
  4. Clone the Cookbook and run getting_started_with_vision — this guide’s #1.
  5. Pick the cookbook notebook closest to what you want to build (#2-10 above).
  6. Modify it for your use case. Replace the example data with your real data.
  7. Iterate on prompts in the Workbench, then port back to your script.
  8. Add observability (logging, evals) before going to production.

Most people who follow this sequence have a working prototype in a weekend.

Frequently asked questions

Do I need to know Python to use the Cookbook?

Yes, basic Python helps. The notebooks are Jupyter (.ipynb files) and run cell-by-cell. You don’t need to be an expert — if you can read and modify variables in a script, you can use the Cookbook. Some examples have TypeScript equivalents in the same repo.

Can I run Cookbook notebooks without paying?

You’ll need an Anthropic API key. The free starter credits on signup cover dozens of cookbook runs. Once those run out, you pay per token. Most notebooks cost $0.01 to $0.50 per full run.

How often is the Cookbook updated?

Anthropic engineers and the community add new notebooks regularly — usually a few per month, with bigger pushes around major releases (new models, new features). Watch the repo on GitHub to get notified of new examples.

Can I contribute my own examples to the Cookbook?

Yes — it’s an open-source repository. Submit a PR with your notebook. Anthropic reviews and merges community contributions. Good candidates: novel patterns, third-party integrations, domain-specific examples (legal, medical, finance) that are widely useful.

Is there a TypeScript or JavaScript version?

Some notebooks have TypeScript equivalents in the same repo (look for .ts companion files). For a more comprehensive TS-first experience, the Anthropic TypeScript SDK has examples in its own repo at github.com/anthropics/anthropic-sdk-typescript.

What’s the difference between the Cookbook and the docs?

The docs are reference material — explanations, API specs, conceptual guides. The Cookbook is working code you can run. Use the docs to understand what something is; use the Cookbook to see exactly how to do it. They complement each other.

Stay current on new Cookbook examples

Hear when new Cookbook examples ship

Free daily newsletter — one story, one tool, one tip. Plain English, no jargon. One issue per day.

Free forever. Unsubscribe anytime.

You may also like

Sources

Two ways to go further

The AI Prompt Library

1,000+ ready-to-use prompts for Claude, ChatGPT, and Gemini. Stop staring at a blank box.

Get it for $39 →

2-Hour Live AI Crash Course

A private, beginner-friendly session across Claude, ChatGPT, Gemini, and the wider landscape.

Book for $125 →

Discover more from Beginners in AI

Subscribe now to keep reading and get access to the full archive.

Continue reading