Module 2 - Lesson 2: Anthropic Claude Prompts Overview
Comprehensive guide to Anthropic Claude prompting techniques and patterns.
Published: 1/10/2026
Anthropic Claude Prompts: From Basic to Advanced
This lesson covers essential Anthropic Claude prompting techniques, mirroring what you learned with OpenAI in Module 1, but with Anthropic's unique approach and features.
Lesson Structure
Each sub-lesson focuses on a specific prompting technique with working code examples. Follow them in order to build your understanding progressively while comparing with OpenAI's approach.
š Prompt Techniques Overview
Lesson 2a: Basic Prompt
Simple text input prompt with Anthropic Claude.
- Send a basic text prompt to Claude
- Understand Anthropic's response structure
- Learn about required
max_tokensparameter - Use Case: Quick, straightforward queries
- Key Difference: Response is an array of content blocks
Lesson 2b: System Prompt
Defining AI role and behavior with system prompts.
- Set Claude's personality and expertise
- Use separate
systemparameter - Control response style and tone
- Use Case: Specialized assistants (travel agent, code reviewer, etc.)
- Key Difference: System prompt is a top-level parameter, not in messages array
Lesson 2c: Temperature Control
Adjusting response creativity with the temperature parameter.
- Learn how temperature affects randomness in Claude
- Balance creativity vs consistency
- Understand Anthropic's temperature range (0.0 - 1.0)
- Use Case: Creative writing (high temp) vs factual responses (low temp)
- Key Difference: Range is 0.0-1.0 (vs OpenAI's 0.0-2.0)
Lesson 2d: Extended Prompts
Detailed context and instructions for advanced prompt engineering.
- Provide comprehensive background information
- Use detailed instructions for complex tasks
- Leverage Claude's large context window (200k tokens)
- Use Case: Complex analysis, detailed planning, multi-step reasoning
- Key Difference: Claude excels at very long, detailed prompts
Lesson 2e: Streaming Responses
Real-time output with streaming responses.
- Stream Claude responses word-by-word
- Use
.stream()method with event handlers - Handle partial responses
- Use Case: Chat interfaces, real-time assistants
- Key Difference: Uses
.on("text")event handler vs OpenAI's async iterator
Lesson 2f: Structured Output
Validated JSON output using Zod.
- Request JSON responses from Claude
- Validate with Zod schemas
- Handle markdown code block wrappers
- Use Case: Data extraction, form filling, API integrations
- Key Difference: Prompt-based approach (Claude doesn't have native structured output yet)
Lesson 2g: Function/Tool Calling
Integrating external APIs and tools with function calling.
- Define tools Claude can use
- Handle tool use responses
- Build multi-turn conversations
- Use Case: Weather lookups, database queries, calculations, external integrations
- Key Difference: Different tool response format and conversation flow
Learning Path
Legend:
- šµ Light Blue: Foundation concepts
- š” Light Yellow: Intermediate techniques
- š“ Light Red: Advanced patterns
Quick Reference
| Technique | Complexity | Best For | Module 1 Equivalent |
|---|---|---|---|
| Basic Prompt | ā Beginner | Simple queries | Lesson 3a |
| System Prompt | ā Beginner | Defining AI role | Lesson 3b |
| Temperature | āā Intermediate | Balancing creativity | Lesson 3c |
| Extended Prompts | āā Intermediate | Complex instructions | Lesson 3d |
| Streaming | āā Intermediate | Real-time UIs | Lesson 3e |
| Structured Output | āāā Advanced | Type-safe data | Lesson 3f |
| Function Calling | āāā Advanced | Tool integration | Lesson 3g |
OpenAI vs Anthropic: Side-by-Side
Basic Structure
OpenAI:
const response = await openai.responses.create({ model: "gpt-5-nano", system: "You are helpful", input: "Hello" }); const text = response.output_text;
Anthropic:
const response = await anthropic.messages.create({ model: "claude-haiku-4-5", max_tokens: 1000, system: "You are helpful", messages: [ { role: "user", content: "Hello" } ] }); const text = response.content[0].text;
Key Differences
| Feature | OpenAI | Anthropic |
|---|---|---|
| max_tokens | Optional | Required |
| System prompt | In messages | Separate parameter |
| Response | choices[0].message.content | content[0].text |
| Streaming | stream: true | .stream() method |
| Temperature range | 0.0 - 2.0 | 0.0 - 1.0 |
| Context window | 128k (GPT-4) | 200k (Claude) |
Prerequisites
Before starting these lessons, ensure you have:
- ā Completed Module 1 (OpenAI prompts)
- ā
Anthropic API key configured in
.env - ā
@anthropic-ai/sdkinstalled - ā Understanding of basic prompting concepts
Folder Structure
All Anthropic examples are in src/anthropic/:
src/
āāā anthropic/
ā āāā basic-prompt.ts ā Lesson 2a
ā āāā basic-prompt-with-system.ts ā Lesson 2b
ā āāā basic-prompt-with-temperature.ts ā Lesson 2c
ā āāā extended-prompt.ts ā Lesson 2d
ā āāā stream-prompt.ts ā Lesson 2e
ā āāā structured-output-prompt.ts ā Lesson 2f
ā āāā tools-prompt.ts ā Lesson 2g
āāā openai/ ā Module 1 examples
āāā ...
Getting Started
Start with Lesson 2a: Basic Prompt and work through each lesson sequentially. Each builds on concepts from the previous ones.
Run Examples
# Run an Anthropic example pnpm tsx src/anthropic/basic-prompt.ts # Compare with OpenAI version pnpm tsx src/openai/basic-prompt.ts
Navigation
- Previous: Lesson 1: Module 2 Overview
- Next: Lesson 2a: Basic Prompt
- Module Index: AI SDK Essentials
What You'll Learn
By completing these seven lessons, you'll master:
- ā Anthropic Claude API fundamentals
- ā Key differences from OpenAI
- ā Response structure and parsing
- ā Real-time streaming with events
- ā Prompt-based structured outputs
- ā Tool calling with conversation flow
- ā Multi-provider development skills
Comparison Skills
You'll be able to:
- š Translate OpenAI code to Anthropic
- š Compare provider strengths
- šÆ Choose the right provider for each task
- š ļø Build provider-agnostic applications
Claude's Strengths
When to Choose Anthropic
-
Long Documents
- 200k token context window
- Better retention over long conversations
- Ideal for document analysis
-
Complex Reasoning
- Excellent at multi-step logic
- Strong analytical capabilities
- Thoughtful, nuanced responses
-
Safety & Reliability
- Constitutional AI approach
- Reduced harmful outputs
- Consistent behavior
-
Writing Quality
- Natural, human-like text
- Good at following style guidelines
- Excellent for content creation
Practice Exercises
As you go through the lessons, try these:
-
Compare Responses
- Run the same prompt on both OpenAI and Anthropic
- Note differences in style, length, and quality
-
Measure Performance
- Time response speeds
- Count token usage
- Calculate costs
-
Test Edge Cases
- Very long prompts
- Complex multi-turn conversations
- Structured output reliability
Ready to Begin?
Start with Lesson 2a: Basic Prompt ā
In Lesson 2a, you'll make your first API call to Claude and see how Anthropic's response structure differs from OpenAI's.
Resources
Anthropic Documentation
Code Repository
- GitHub: CWK AI Playground
- Branch:
module-2
Community
Happy coding with Claude! š