Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude/commands/model-check.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: Validate Claude model usage against current public models
Review the changed files for Claude model usage.

First, fetch the current list of allowed models from:
https://docs.anthropic.com/en/docs/about-claude/models/overview.md
https://docs.claude.com/en/docs/about-claude/models/overview.md

Then check:
1. All model references are from the current public models list
Expand Down
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Anthropic API Configuration
# Claude API Configuration
# Copy this file to .env and add your API key
# Get your API key at: https://console.anthropic.com/settings/keys

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/notebook-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
github.event.pull_request.author_association == 'MEMBER' ||
github.event.pull_request.author_association == 'OWNER'
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
mkdir -p test_outputs
for notebook in $(find . -name "*.ipynb" -not -path "*/.*" -not -path "*/test_outputs/*"); do
Expand Down
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Contributing to Anthropic Cookbook
# Contributing to Claude Cookbook

Thank you for your interest in contributing to the Anthropic Cookbook! This guide will help you get started with development and ensure your contributions meet our quality standards.
Thank you for your interest in contributing to the Claude Cookbook! This guide will help you get started with development and ensure your contributions meet our quality standards.

## Development Setup

Expand Down Expand Up @@ -45,7 +45,7 @@ Thank you for your interest in contributing to the Anthropic Cookbook! This guid
5. **Set up your API key**:
```bash
cp .env.example .env
# Edit .env and add your Anthropic API key
# Edit .env and add your Claude API key
```

## Quality Standards
Expand Down Expand Up @@ -118,7 +118,7 @@ If a hook fails, fix the issues and try committing again.

2. **Use current Claude models**:
- Use model aliases (e.g., `claude-3-5-haiku-latest`) for better maintainability
- Check current models at: https://docs.anthropic.com/en/docs/about-claude/models/overview
- Check current models at: https://docs.claude.com/en/docs/about-claude/models/overview
- Claude will automatically validate model usage in PR reviews

3. **Keep notebooks focused**:
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# Anthropic Cookbook
# Claude Cookbook

The Anthropic Cookbook provides code and guides designed to help developers build with Claude, offering copy-able code snippets that you can easily integrate into your own projects.
The Claude Cookbook provides code and guides designed to help developers build with Claude, offering copy-able code snippets that you can easily integrate into your own projects.

## Prerequisites

To make the most of the examples in this cookbook, you'll need an Anthropic API key (sign up for free [here](https://www.anthropic.com)).
To make the most of the examples in this cookbook, you'll need an Claude API key (sign up for free [here](https://www.anthropic.com)).

While the code examples are primarily written in Python, the concepts can be adapted to any programming language that supports interaction with the Anthropic API.
While the code examples are primarily written in Python, the concepts can be adapted to any programming language that supports interaction with the Claude API.

If you're new to working with the Anthropic API, we recommend starting with our [Anthropic API Fundamentals course](https://github.com/anthropics/courses/tree/master/anthropic_api_fundamentals) to get a solid foundation.
If you're new to working with the Claude API, we recommend starting with our [Claude API Fundamentals course](https://github.com/anthropics/courses/tree/master/anthropic_api_fundamentals) to get a solid foundation.

## Explore Further

Looking for more resources to enhance your experience with Claude and AI assistants? Check out these helpful links:

- [Anthropic developer documentation](https://docs.anthropic.com/claude/docs/guide-to-anthropics-prompt-engineering-resources)
- [Anthropic developer documentation](https://docs.claude.com/claude/docs/guide-to-anthropics-prompt-engineering-resources)
- [Anthropic support docs](https://support.anthropic.com)
- [Anthropic Discord community](https://www.anthropic.com/discord)

## Contributing

The Anthropic Cookbook thrives on the contributions of the developer community. We value your input, whether it's submitting an idea, fixing a typo, adding a new guide, or improving an existing one. By contributing, you help make this resource even more valuable for everyone.
The Claude Cookbook thrives on the contributions of the developer community. We value your input, whether it's submitting an idea, fixing a typo, adding a new guide, or improving an existing one. By contributing, you help make this resource even more valuable for everyone.

To avoid duplication of efforts, please review the existing issues and pull requests before contributing.

Expand Down
2 changes: 1 addition & 1 deletion claude_code_sdk/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Create a token at: https://github.com/settings/tokens
GITHUB_TOKEN="your-github-personal-access-token-here"

# Anthropic API Key
# Claude API Key
# Required for using Claude SDK
# Get your key at: https://console.anthropic.com/settings/keys
ANTHROPIC_API_KEY="sk-ant-api03-your-api-key-here"
6 changes: 3 additions & 3 deletions claude_code_sdk/00_The_one_liner_research_agent.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
"\n",
"Instead, a research agent requires the flexibility to explore unexpected leads and change direction based on what it finds. In its simplest form, a research agent can be an agent that simply searches the internet and summarizes it for you. \n",
"\n",
"Below, we'll implement a basic research agent with just a few lines of code. We provide Claude with exactly one tool which the Claude Code SDK contains straight out of the box: [web search tool](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/web-search-tool). \n",
"Below, we'll implement a basic research agent with just a few lines of code. We provide Claude with exactly one tool which the Claude Code SDK contains straight out of the box: [web search tool](https://docs.claude.com/en/docs/agents-and-tools/tool-use/web-search-tool). \n",
"\n",
"> Check [here](https://docs.anthropic.com/en/docs/claude-code/settings#tools-available-to-claude) for a list of Claude Code's readily available tools"
"> Check [here](https://docs.claude.com/en/docs/claude-code/settings#tools-available-to-claude) for a list of Claude Code's readily available tools"
]
},
{
Expand Down Expand Up @@ -120,7 +120,7 @@
"\n",
"So far, we have laid out a very simple (maybe naive) implementation to illustrate how you can start leveraging the SDK to build a research agent. However, there are various ways we can improve our agent to turn it production ready. Let's cover a few of them:\n",
"\n",
"1. Notice how before we only sent one query? In many systems, a human will look at the output of the system, potentially assigning a follow up task. Just like text completions, if we want to send multiple queries to the agent (e.g., 1. analyze abc, 2. make xyz based on your analysis) we would have to copy over the entire analysis context in our second query. Instead, we can **[use the ClaudeSDKClient](https://docs.anthropic.com/en/docs/claude-code/sdk/sdk-python#1-the-claudesdkclient-class-recommended)** to maintain the conversation context for us.\n",
"1. Notice how before we only sent one query? In many systems, a human will look at the output of the system, potentially assigning a follow up task. Just like text completions, if we want to send multiple queries to the agent (e.g., 1. analyze abc, 2. make xyz based on your analysis) we would have to copy over the entire analysis context in our second query. Instead, we can **[use the ClaudeSDKClient](https://docs.claude.com/en/docs/claude-code/sdk/sdk-python#1-the-claudesdkclient-class-recommended)** to maintain the conversation context for us.\n",
"\n",
"2. Another great way of steering the system is **providing a system prompt**, akin to a system prompt used for text completions. To learn how to write a good system prompt for a research agent, we recommend looking [here](https://github.com/anthropics/anthropic-cookbook/tree/main/patterns/agents/prompts).\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion claude_code_sdk/02_The_observability_agent.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"cell_type": "markdown",
"id": "08cc95b6",
"metadata": {},
"source": "In the previous notebooks we have built a basic research agent and a Chief of Staff multi-agent framework. While the agents we have built are already powerful, they were still limited in what they could do: the web search agent is limited to searching the internet and our Chief of Staff agent was limited to interacting with its own filesystem.\n\nThis is a serious constraint: real-world agents often need to interact with other systems like databases, APIs, file systems, and other specialized services. [MCP (Model Context Protocol)](https://modelcontextprotocol.io/docs/getting-started/intro) is an open-source standard for AI-tool integrations that allows for an easy connection between our agents and these external systems. In this notebook, we will explore how to connect MCP servers to our agent.\n\n**Need more details on MCP?** For comprehensive setup instructions, configuration best practices, and troubleshooting tips, see the [Claude Code MCP documentation](https://docs.anthropic.com/en/docs/claude-code/mcp)."
"source": "In the previous notebooks we have built a basic research agent and a Chief of Staff multi-agent framework. While the agents we have built are already powerful, they were still limited in what they could do: the web search agent is limited to searching the internet and our Chief of Staff agent was limited to interacting with its own filesystem.\n\nThis is a serious constraint: real-world agents often need to interact with other systems like databases, APIs, file systems, and other specialized services. [MCP (Model Context Protocol)](https://modelcontextprotocol.io/docs/getting-started/intro) is an open-source standard for AI-tool integrations that allows for an easy connection between our agents and these external systems. In this notebook, we will explore how to connect MCP servers to our agent.\n\n**Need more details on MCP?** For comprehensive setup instructions, configuration best practices, and troubleshooting tips, see the [Claude Code MCP documentation](https://docs.claude.com/en/docs/claude-code/mcp)."
},
{
"cell_type": "markdown",
Expand Down
2 changes: 1 addition & 1 deletion claude_code_sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ A tutorial series demonstrating how to build sophisticated general-purpose agent

```uv run python -m ipykernel install --user --name="cc-sdk-tutorial" --display-name "Python (cc-sdk-tutorial)" ```

#### 4. Anthropic API Key
#### 4. Claude API Key
1. Visit [console.anthropic.com](https://console.anthropic.com/dashboard)
2. Sign up or log in to your account
3. Click on "Get API keys"
Expand Down
4 changes: 2 additions & 2 deletions extended_thinking/extended_thinking.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"\n",
"This notebook demonstrates how to use Claude 3.7 Sonnet's extended thinking feature with various examples and edge cases.\n",
"\n",
"Extended thinking gives Claude 3.7 Sonnet enhanced reasoning capabilities for complex tasks, while also providing transparency into its step-by-step thought process before it delivers its final answer. When extended thinking is turned on, Claude creates `thinking` content blocks where it outputs its internal reasoning. Claude incorporates insights from this reasoning before crafting a final response. For more information on extended thinking, see our [documentation](https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking)."
"Extended thinking gives Claude 3.7 Sonnet enhanced reasoning capabilities for complex tasks, while also providing transparency into its step-by-step thought process before it delivers its final answer. When extended thinking is turned on, Claude creates `thinking` content blocks where it outputs its internal reasoning. Claude incorporates insights from this reasoning before crafting a final response. For more information on extended thinking, see our [documentation](https://docs.claude.com/en/docs/build-with-claude/extended-thinking)."
]
},
{
Expand Down Expand Up @@ -561,7 +561,7 @@
"\n",
"Error with too small thinking budget: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'thinking.enabled.budget_tokens: Input should be greater than or equal to 1024'}}\n",
"\n",
"Error with temperature and thinking: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': '`temperature` may only be set to 1 when thinking is enabled. Please consult our documentation at https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking#important-considerations-when-using-extended-thinking'}}\n",
"Error with temperature and thinking: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': '`temperature` may only be set to 1 when thinking is enabled. Please consult our documentation at https://docs.claude.com/en/docs/build-with-claude/extended-thinking#important-considerations-when-using-extended-thinking'}}\n",
"\n",
"Error from exceeding context window: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'prompt is too long: 214315 tokens > 204798 maximum'}}\n"
]
Expand Down
4 changes: 2 additions & 2 deletions extended_thinking/extended_thinking_with_tool_use.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"\n",
"This notebook demonstrates how to use Claude 3.7 Sonnet's extended thinking feature with tools. The extended thinking feature allows you to see Claude's step-by-step thinking before it provides a final answer, providing transparency into how it decides which tools to use and how it interprets tool results.\n",
"\n",
"When using extended thinking with tool use, the model will show its thinking before making tool requests, but not repeat the thinking process after receiving tool results. Claude will not output another thinking block until after the next non-`tool_result` `user` turn. For more information on extended thinking, see our [documentation](https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking)."
"When using extended thinking with tool use, the model will show its thinking before making tool requests, but not repeat the thinking process after receiving tool results. Claude will not output another thinking block until after the next non-`tool_result` `user` turn. For more information on extended thinking, see our [documentation](https://docs.claude.com/en/docs/build-with-claude/extended-thinking)."
]
},
{
Expand Down Expand Up @@ -656,7 +656,7 @@
"Tool result: {'temperature': 60, 'condition': 'Foggy'}\n",
"\n",
"=== TEST 1: WITHOUT thinking block ===\n",
"ERROR: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'messages.1.content.0.type: Expected `thinking` or `redacted_thinking`, but found `tool_use`. When `thinking` is enabled, a final `assistant` message must start with a thinking block (preceeding the lastmost set of `tool_use` and `tool_result` blocks). We recommend you include thinking blocks from previous turns. To avoid this requirement, disable `thinking`. Please consult our documentation at https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking'}}\n",
"ERROR: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'messages.1.content.0.type: Expected `thinking` or `redacted_thinking`, but found `tool_use`. When `thinking` is enabled, a final `assistant` message must start with a thinking block (preceeding the lastmost set of `tool_use` and `tool_result` blocks). We recommend you include thinking blocks from previous turns. To avoid this requirement, disable `thinking`. Please consult our documentation at https://docs.claude.com/en/docs/build-with-claude/extended-thinking'}}\n",
"This demonstrates that thinking blocks must be preserved\n",
"\n",
"=== TEST 2: WITH thinking block (correct approach) ===\n",
Expand Down
2 changes: 1 addition & 1 deletion lychee.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Lychee configuration for Anthropic Cookbook
# Lychee configuration for Claude Cookbook
# Validates links in notebooks and documentation

# Core settings
Expand Down
2 changes: 1 addition & 1 deletion misc/building_moderation_filter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"Based on the guidelines above, classify this text as either ALLOW or BLOCK. Return nothing else.\n",
"```\n",
"\n",
"To use this, you would replace `{{USER_TEXT}}` with the actual user-generated text to be classified, and then send the prompt to Claude using the Anthropic API. Claude's response should be either \"ALLOW\" or \"BLOCK\", indicating how the text should be handled based on your provided guidelines."
"To use this, you would replace `{{USER_TEXT}}` with the actual user-generated text to be classified, and then send the prompt to Claude using the Claude API. Claude's response should be either \"ALLOW\" or \"BLOCK\", indicating how the text should be handled based on your provided guidelines."
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions misc/generate_test_cases.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"\n",
"Here we'd call thing1 and thing2 the \"variables\" -- and you want your prompt to behave well for many different possible values of thing1 and thing2.\n",
"\n",
"How can you test this prompt template? Maybe you have some real-life values you can substitute in. But maybe you don't, or maybe you aren't allowed to test on the ones you do have for privacy reasons. No worries -- Claude can make them up! This cookbook demonstrates how to generate synthetic test data for your prompts using Claude & the Anthropic API. It includes functions for extracting variables from templates, constructing example blocks, generating test cases, and iteratively refining the results. The benefits of this are twofold:\n",
"How can you test this prompt template? Maybe you have some real-life values you can substitute in. But maybe you don't, or maybe you aren't allowed to test on the ones you do have for privacy reasons. No worries -- Claude can make them up! This cookbook demonstrates how to generate synthetic test data for your prompts using Claude & the Claude API. It includes functions for extracting variables from templates, constructing example blocks, generating test cases, and iteratively refining the results. The benefits of this are twofold:\n",
"\n",
"1. Prompt Evaluation\n",
"You can use these test cases to see how Claude will perform on realistic examples.\n",
Expand Down Expand Up @@ -241,7 +241,7 @@
"outputs": [],
"source": [
"def get_test_data(prompt_template, examples, custom_planning=None):\n",
" \"\"\"Generate test data using the Anthropic API.\"\"\"\n",
" \"\"\"Generate test data using the Claude API.\"\"\"\n",
" synth_eval_prompt_ready = format_prompt_template_for_synth_evals(prompt_template, examples)\n",
"\n",
" messages = [\n",
Expand Down
2 changes: 1 addition & 1 deletion misc/how_to_make_sql_queries.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"from anthropic import Anthropic\n",
"import sqlite3\n",
"\n",
"# Set up the Anthropic API client\n",
"# Set up the Claude API client\n",
"client = Anthropic()\n",
"MODEL_NAME = \"claude-3-opus-20240229\""
]
Expand Down
2 changes: 1 addition & 1 deletion misc/illustrated_responses.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"outputs": [],
"source": [
"STABILITY_API_KEY = \"\" # Stability API key goes here\n",
"ANTHROPIC_API_KEY = \"\" # Anthropic API key goes here\n",
"ANTHROPIC_API_KEY = \"\" # Claude API key goes here\n",
"MODEL_NAME = \"claude-3-opus-20240229\"\n",
"CLIENT = anthropic.Anthropic(api_key=ANTHROPIC_API_KEY)"
]
Expand Down
2 changes: 1 addition & 1 deletion misc/metaprompt.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"source": [
"### Using This Notebook\n",
"The notebook is designed to be maximally easy to use. You don't have to write any code. Just follow these steps:\n",
"- Enter your Anthropic API key in between quotation marks where it says \"Put your API key here!\"\n",
"- Enter your Claude API key in between quotation marks where it says \"Put your API key here!\"\n",
"- Enter your task where it says \"Replace with your task!\"\n",
"- Optionally, enter an all-caps list of variables in quotes separated by commas where it says \"specify the input variables you want Claude to use\".\n",
"\n",
Expand Down
Loading
Loading