Best use case
Anthropic SDK is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
## Overview
Teams using Anthropic SDK should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/anthropic-sdk/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How Anthropic SDK Compares
| Feature / Agent | Anthropic SDK | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
## Overview
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Anthropic SDK
## Overview
The Anthropic SDK provides access to Claude models (Opus, Sonnet, Haiku) for text generation, analysis, coding, and reasoning. Claude excels at long-context understanding (200K tokens), careful instruction following, code generation, and complex reasoning. This skill covers the Messages API, streaming, tool use (function calling), vision, extended thinking, system prompts, and best practices for prompt engineering with Claude.
## Instructions
### Step 1: Installation
```bash
# Node.js
npm install @anthropic-ai/sdk
# Python
pip install anthropic
```
```typescript
// lib/anthropic.ts — Client initialization
import Anthropic from '@anthropic-ai/sdk'
const anthropic = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY,
})
```
### Step 2: Messages API
```typescript
// chat.ts — Basic message creation
const message = await anthropic.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
system: 'You are a senior software engineer. Provide clear, production-ready code with comments.',
messages: [
{ role: 'user', content: 'Write a rate limiter middleware for Express.js using a sliding window algorithm.' },
],
})
console.log(message.content[0].type === 'text' ? message.content[0].text : '')
// message.usage: { input_tokens: 42, output_tokens: 512 }
```
```python
# Python equivalent
import anthropic
client = anthropic.Anthropic()
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
system="You are a senior software engineer.",
messages=[
{"role": "user", "content": "Write a rate limiter for Express.js."}
],
)
print(message.content[0].text)
```
### Step 3: Streaming
```typescript
// stream.ts — Stream responses for real-time UI
const stream = anthropic.messages.stream({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Explain how B-trees work.' }],
})
for await (const event of stream) {
if (event.type === 'content_block_delta' && event.delta.type === 'text_delta') {
process.stdout.write(event.delta.text)
}
}
// Or using the helper
const stream2 = anthropic.messages.stream({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Explain B-trees.' }],
})
stream2.on('text', (text) => process.stdout.write(text))
await stream2.finalMessage()
```
### Step 4: Tool Use (Function Calling)
```typescript
// tools.ts — Let Claude call your functions
const tools: Anthropic.Tool[] = [
{
name: 'get_stock_price',
description: 'Get the current stock price for a ticker symbol. Use when the user asks about stock prices.',
input_schema: {
type: 'object',
properties: {
ticker: { type: 'string', description: 'Stock ticker symbol (e.g., AAPL, GOOGL)' },
},
required: ['ticker'],
},
},
{
name: 'execute_sql',
description: 'Execute a read-only SQL query against the analytics database.',
input_schema: {
type: 'object',
properties: {
query: { type: 'string', description: 'SQL SELECT query to execute' },
},
required: ['query'],
},
},
]
const response = await anthropic.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
tools,
messages: [{ role: 'user', content: 'What is Apple stock at right now?' }],
})
// Process tool use
if (response.stop_reason === 'tool_use') {
const toolUse = response.content.find(b => b.type === 'tool_use')!
const result = await executeFunction(toolUse.name, toolUse.input)
// Send result back to Claude
const finalResponse = await anthropic.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
tools,
messages: [
{ role: 'user', content: 'What is Apple stock at right now?' },
{ role: 'assistant', content: response.content },
{ role: 'user', content: [{ type: 'tool_result', tool_use_id: toolUse.id, content: JSON.stringify(result) }] },
],
})
}
```
### Step 5: Vision
```typescript
// vision.ts — Analyze images with Claude
import { readFileSync } from 'fs'
// URL-based image
const response = await anthropic.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
messages: [{
role: 'user',
content: [
{ type: 'image', source: { type: 'url', url: 'https://example.com/chart.png' } },
{ type: 'text', text: 'Analyze this chart. What trends do you see?' },
],
}],
})
// Base64 image (from file)
const imageData = readFileSync('screenshot.png').toString('base64')
const response2 = await anthropic.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
messages: [{
role: 'user',
content: [
{ type: 'image', source: { type: 'base64', media_type: 'image/png', data: imageData } },
{ type: 'text', text: 'Extract all text and data from this screenshot.' },
],
}],
})
```
### Step 6: Extended Thinking
```typescript
// thinking.ts — Enable extended thinking for complex reasoning tasks
const response = await anthropic.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 16000,
thinking: {
type: 'enabled',
budget_tokens: 10000, // tokens allocated for internal reasoning
},
messages: [{
role: 'user',
content: 'Analyze this codebase for security vulnerabilities and provide a prioritized remediation plan.',
}],
})
// Response contains both thinking blocks and text blocks
for (const block of response.content) {
if (block.type === 'thinking') {
console.log('Reasoning:', block.thinking)
} else if (block.type === 'text') {
console.log('Response:', block.text)
}
}
```
### Step 7: Multi-Turn Conversations
```typescript
// conversation.ts — Maintain conversation history
const messages: Anthropic.MessageParam[] = []
async function chat(userMessage: string): Promise<string> {
messages.push({ role: 'user', content: userMessage })
const response = await anthropic.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 2048,
system: 'You are a helpful assistant for a project management app.',
messages,
})
const assistantContent = response.content
messages.push({ role: 'assistant', content: assistantContent })
return assistantContent.filter(b => b.type === 'text').map(b => b.text).join('')
}
```
## Examples
### Example 1: Build a code review bot
**User prompt:** "Build a bot that reviews pull requests. It should analyze the diff, check for bugs, security issues, and style problems, then post inline comments."
The agent will:
1. Fetch PR diff via GitHub API.
2. Send the diff to Claude with a system prompt tuned for code review.
3. Use structured output to get file-specific comments with line numbers.
4. Post comments back to GitHub using the PR review API.
### Example 2: Document analysis pipeline with tool use
**User prompt:** "Build a system where users upload contracts and ask questions about them. The AI should be able to search across multiple documents and cite specific sections."
The agent will:
1. Store document chunks with embeddings in a vector database.
2. Define a `search_documents` tool that Claude can call.
3. Claude formulates search queries, retrieves relevant chunks, and synthesizes answers with citations.
4. Use Claude's 200K context window for full-document analysis when documents are small enough.
## Guidelines
- Claude Sonnet is the best default for most tasks — it balances quality, speed, and cost. Use Opus for the most complex reasoning and Haiku for high-volume, simple tasks.
- Write detailed system prompts — Claude follows instructions carefully. Specify output format, constraints, tone, and edge case handling in the system prompt.
- Use extended thinking for complex reasoning (math, multi-step analysis, code architecture). The thinking budget controls how much Claude reasons before responding.
- Claude supports 200K token context windows — use this for long document analysis, large codebases, and conversations with extensive history.
- For tool use, provide clear descriptions and examples in the tool definition. Claude uses descriptions (not just parameter names) to decide when and how to call tools.
- Always handle the `stop_reason` field: `end_turn` means done, `tool_use` means Claude wants to call a function, `max_tokens` means the response was truncated.Related Skills
internal-comms-anthropic
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill whenever asked to write some sort of internal ...
brand-guidelines-anthropic
Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatt...
Anthropic's official skill authoring best practices
Apply Anthropic's official skill authoring best practices to your skill.
anthropic-administrator-automation
Automate Anthropic Admin tasks via Rube MCP (Composio): API keys, usage, workspaces, and organization management. Always search tools first for current schemas.
Daily Logs
Record the user's daily activities, progress, decisions, and learnings in a structured, chronological format.
Socratic Method: The Dialectic Engine
This skill transforms Claude into a Socratic agent — a cognitive partner who guides
Sokratische Methode: Die Dialektik-Maschine
Dieser Skill verwandelt Claude in einen sokratischen Agenten — einen kognitiven Partner, der Nutzende durch systematisches Fragen zur Wissensentdeckung führt, anstatt direkt zu instruieren.
College Football Data (CFB)
Before writing queries, consult `references/api-reference.md` for endpoints, conference IDs, team IDs, and data shapes.
College Basketball Data (CBB)
Before writing queries, consult `references/api-reference.md` for endpoints, conference IDs, team IDs, and data shapes.
Betting Analysis
Before writing queries, consult `references/api-reference.md` for odds formats, command parameters, and key concepts.
Research Proposal Generator
Generate high-quality academic research proposals for PhD applications following Nature Reviews-style academic writing conventions.
Paper Slide Deck Generator
Transform academic papers and content into professional slide deck images with automatic figure extraction.