anthropic-sdk
Anthropic SDKは、Claude AIをアプリに組み込み、テキスト生成やチャットボット開発、長文処理、ツール連携、コード生成、文書分析など、Claudeの様々な機能を活用できるようにするSkill。
📜 元の英語説明(参考)
Integrate Claude AI into applications with the Anthropic SDK. Use when a user asks to add Claude to an app, use Claude for text generation, build a chatbot with Claude, use Claude's long context window, implement tool use with Claude, stream Claude responses, use Claude for code generation, document analysis, or reasoning tasks. Covers Messages API, streaming, tool use, vision, system prompts, extended thinking, and batch processing.
🇯🇵 日本人クリエイター向け解説
Anthropic SDKは、Claude AIをアプリに組み込み、テキスト生成やチャットボット開発、長文処理、ツール連携、コード生成、文書分析など、Claudeの様々な機能を活用できるようにするSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o anthropic-sdk.zip https://jpskill.com/download/14632.zip && unzip -o anthropic-sdk.zip && rm anthropic-sdk.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/14632.zip -OutFile "$d\anthropic-sdk.zip"; Expand-Archive "$d\anthropic-sdk.zip" -DestinationPath $d -Force; ri "$d\anthropic-sdk.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
anthropic-sdk.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
anthropic-sdkフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
Anthropic SDK
概要
Anthropic SDK は、テキスト生成、分析、コーディング、および推論のための Claude モデル (Opus、Sonnet、Haiku) へのアクセスを提供します。Claude は、長文コンテキストの理解 (200K トークン)、注意深い指示の遵守、コード生成、および複雑な推論に優れています。このスキルでは、Messages API、ストリーミング、ツール使用 (関数呼び出し)、ビジョン、拡張思考、システムプロンプト、および Claude を使用したプロンプトエンジニアリングのベストプラクティスについて説明します。
手順
ステップ 1: インストール
# Node.js
npm install @anthropic-ai/sdk
# Python
pip install anthropic
// lib/anthropic.ts — クライアントの初期化
import Anthropic from '@anthropic-ai/sdk'
const anthropic = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY,
})
ステップ 2: Messages API
// chat.ts — 基本的なメッセージの作成
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 での同等の記述
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)
ステップ 3: ストリーミング
// stream.ts — リアルタイム 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)
}
}
// またはヘルパーを使用する
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()
ステップ 4: ツール使用 (関数呼び出し)
// tools.ts — Claude に関数を呼び出させる
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?' }],
})
// ツール使用の処理
if (response.stop_reason === 'tool_use') {
const toolUse = response.content.find(b => b.type === 'tool_use')!
const result = await executeFunction(toolUse.name, toolUse.input)
// 結果を 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) }] },
],
})
}
ステップ 5: ビジョン
// vision.ts — Claude で画像を分析する
import { readFileSync } from 'fs'
// URL ベースの画像
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 画像 (ファイルから)
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.' },
],
}],
})
ステップ 6: 拡張思考
// thinking.ts — 複雑な推論タスクのために拡張思考を有効にする
const response = await anthropic.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 16000,
thinking: {
type: 'enabled',
budget_tokens: 10000, // 内部推論に割り当てられたトークン
},
messages: [{
role: 'user',
content: 'Analyze this codebase for security vulnerabilities and provide a prioritized remediation plan.',
}],
})
// 応答には、思考ブロックとテキストブロックの両方が含まれます
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)
}
}
ステップ 7: 複数ターンの会話
// conversation.ts — 会話履歴を維持する
const messages: Anthropic.MessageParam[] = []
async function chat(userMessage: string): Promise<string> {
messages.push({ role: 'user', content: userMessage })
const response = awai 📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
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
# Node.js
npm install @anthropic-ai/sdk
# Python
pip install anthropic
// 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
// 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 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
// 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)
// 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
// 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
// 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
// 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:
- Fetch PR diff via GitHub API.
- Send the diff to Claude with a system prompt tuned for code review.
- Use structured output to get file-specific comments with line numbers.
- 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:
- Store document chunks with embeddings in a vector database.
- Define a
search_documentstool that Claude can call. - Claude formulates search queries, retrieves relevant chunks, and synthesizes answers with citations.
- 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_reasonfield:end_turnmeans done,tool_usemeans Claude wants to call a function,max_tokensmeans the response was truncated.