クイックスタート
Claude Agent Skills と API を使ってドキュメントを作成する。
Agent Skills を使い、Claude API で 10 分以内にドキュメントを作成する方法を学びます。
このチュートリアルでは、Agent Skills を使って PowerPoint プレゼンテーションを作成します。Skills を有効にする方法、簡単なリクエストを送る方法、生成されたファイルへアクセスする方法を順番に学びます。
前提条件
- Anthropic API キー
- Python 3.7 以降、または curl がインストールされていること
- API リクエストの基本的な知識
Agent Skills とは
事前構築済みの Agent Skills は、ドキュメント作成、データ分析、ファイル処理のようなタスクに向けた専門知識で Claude の能力を拡張します。Anthropic は、API で次の事前構築済み Agent Skills を提供しています。
- PowerPoint (pptx): プレゼンテーションの作成と編集
- Excel (xlsx): スプレッドシートの作成と分析
- Word (docx): 文書の作成と編集
- PDF (pdf): PDF ドキュメントの生成
注記
カスタム Skills を作りたいですか? 領域固有の専門知識を備えた独自 Skills の構築例は、Agent Skills Cookbook を参照してください。
ステップ 1: 利用可能な Skills を一覧表示する
まず、どの Skills が利用できるかを確認します。Skills API を使って、Anthropic が管理するすべての Skills を一覧表示します。
import anthropic
client = anthropic.Anthropic()
# Anthropic が管理する Skills を一覧表示する
skills = client.beta.skills.list(
source="anthropic",
betas=["skills-2025-10-02"]
)
for skill in skills.data:
print(f"{skill.id}: {skill.display_title}")import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic();
// Anthropic が管理する Skills を一覧表示する
const skills = await client.beta.skills.list({
source: 'anthropic',
betas: ['skills-2025-10-02']
});
for (const skill of skills.data) {
console.log(`${skill.id}: ${skill.display_title}`);
}curl "https://api.anthropic.com/v1/skills?source=anthropic" \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: skills-2025-10-02"次の Skills が表示されます: pptx、xlsx、docx、pdf。
この API は各 Skill のメタデータ、つまり名前と説明を返します。Claude は起動時にこのメタデータを読み込み、利用可能な Skills を把握します。これが 段階的開示の最初のレベルです。Claude はこの段階では各 Skill の完全な指示を読み込まず、どの Skills があるかだけを発見します。
ステップ 2: プレゼンテーションを作成する
次に、PowerPoint Skill を使って再生可能エネルギーに関するプレゼンテーションを作成します。Messages API の container パラメータで Skills を指定します。
import anthropic
client = anthropic.Anthropic()
# PowerPoint Skill を使ってメッセージを作成する
response = client.beta.messages.create(
model="claude-sonnet-4-5-20250929",
max_tokens=4096,
betas=["code-execution-2025-08-25", "skills-2025-10-02"],
container={
"skills": [
{
"type": "anthropic",
"skill_id": "pptx",
"version": "latest"
}
]
},
messages=[{
"role": "user",
"content": "再生可能エネルギーについて、5 枚のスライドでプレゼンテーションを作成してください"
}],
tools=[{
"type": "code_execution_20250825",
"name": "code_execution"
}]
)
print(response.content)import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic();
// PowerPoint Skill を使ってメッセージを作成する
const response = await client.beta.messages.create({
model: 'claude-sonnet-4-5-20250929',
max_tokens: 4096,
betas: ['code-execution-2025-08-25', 'skills-2025-10-02'],
container: {
skills: [
{
type: 'anthropic',
skill_id: 'pptx',
version: 'latest'
}
]
},
messages: [{
role: 'user',
content: '再生可能エネルギーについて、5 枚のスライドでプレゼンテーションを作成してください'
}],
tools: [{
type: 'code_execution_20250825',
name: 'code_execution'
}]
});
console.log(response.content);curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: code-execution-2025-08-25,skills-2025-10-02" \
-H "content-type: application/json" \
-d '{
"model": "claude-sonnet-4-5-20250929",
"max_tokens": 4096,
"container": {
"skills": [
{
"type": "anthropic",
"skill_id": "pptx",
"version": "latest"
}
]
},
"messages": [{
"role": "user",
"content": "再生可能エネルギーについて、5 枚のスライドでプレゼンテーションを作成してください"
}],
"tools": [{
"type": "code_execution_20250825",
"name": "code_execution"
}]
}'各部分の役割を分解して見てみましょう。
container.skills: Claude が使用できる Skills を指定しますtype: "anthropic": これが Anthropic 管理の Skill であることを示しますskill_id: "pptx": PowerPoint Skill の識別子ですversion: "latest": Skill のバージョンを、直近で公開されたものに設定しますtools: コード実行を有効にします。Skills には必須です- Beta headers:
code-execution-2025-08-25とskills-2025-10-02
このリクエストを送ると、Claude はタスクに関連する Skill を自動的に照合します。プレゼンテーションを依頼しているため、Claude は PowerPoint Skill が関連すると判断し、その完全な指示を読み込みます。これが段階的開示の 2 つ目のレベルです。その後、Claude は Skill のコードを実行してプレゼンテーションを作成します。
ステップ 3: 作成されたファイルをダウンロードする
プレゼンテーションはコード実行コンテナ内で作成され、ファイルとして保存されます。レスポンスには、ファイル ID を含むファイル参照が含まれます。ファイル ID を取り出し、Files API を使ってダウンロードします。
# レスポンスからファイル ID を取り出す
file_id = None
for block in response.content:
if block.type == 'tool_use' and block.name == 'code_execution':
# ファイル ID はツール結果の中にある
for result_block in block.content:
if hasattr(result_block, 'file_id'):
file_id = result_block.file_id
break
if file_id:
# ファイルをダウンロードする
file_content = client.beta.files.download(
file_id=file_id,
betas=["files-api-2025-04-14"]
)
# ディスクに保存する
with open("renewable_energy.pptx", "wb") as f:
file_content.write_to_file(f.name)
print(f"プレゼンテーションを renewable_energy.pptx に保存しました")// レスポンスからファイル ID を取り出す
let fileId: string | null = null;
for (const block of response.content) {
if (block.type === 'tool_use' && block.name === 'code_execution') {
// ファイル ID はツール結果の中にある
for (const resultBlock of block.content) {
if ('file_id' in resultBlock) {
fileId = resultBlock.file_id;
break;
}
}
}
}
if (fileId) {
// ファイルをダウンロードする
const fileContent = await client.beta.files.download(fileId, {
betas: ['files-api-2025-04-14']
});
// ディスクに保存する
const fs = require('fs');
fs.writeFileSync('renewable_energy.pptx', Buffer.from(await fileContent.arrayBuffer()));
console.log('プレゼンテーションを renewable_energy.pptx に保存しました');
}# レスポンスから file_id を取り出す(jq を使用)
FILE_ID=$(echo "$RESPONSE" | jq -r '.content[] | select(.type=="tool_use" and .name=="code_execution") | .content[] | select(.file_id) | .file_id')
# ファイルをダウンロードする
curl "https://api.anthropic.com/v1/files/$FILE_ID/content" \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: files-api-2025-04-14" \
--output renewable_energy.pptx
echo "プレゼンテーションを renewable_energy.pptx に保存しました"注記
生成ファイルの扱いに関する完全な詳細は、コード実行ツールのドキュメント を参照してください。
さらに試す例
Skills で最初のドキュメントを作成できたので、次のバリエーションも試してみてください。
スプレッドシートを作成する
response = client.beta.messages.create(
model="claude-sonnet-4-5-20250929",
max_tokens=4096,
betas=["code-execution-2025-08-25", "skills-2025-10-02"],
container={
"skills": [
{
"type": "anthropic",
"skill_id": "xlsx",
"version": "latest"
}
]
},
messages=[{
"role": "user",
"content": "サンプルデータを含む四半期売上追跡スプレッドシートを作成してください"
}],
tools=[{
"type": "code_execution_20250825",
"name": "code_execution"
}]
)const response = await client.beta.messages.create({
model: 'claude-sonnet-4-5-20250929',
max_tokens: 4096,
betas: ['code-execution-2025-08-25', 'skills-2025-10-02'],
container: {
skills: [
{
type: 'anthropic',
skill_id: 'xlsx',
version: 'latest'
}
]
},
messages: [{
role: 'user',
content: 'サンプルデータを含む四半期売上追跡スプレッドシートを作成してください'
}],
tools: [{
type: 'code_execution_20250825',
name: 'code_execution'
}]
});curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: code-execution-2025-08-25,skills-2025-10-02" \
-H "content-type: application/json" \
-d '{
"model": "claude-sonnet-4-5-20250929",
"max_tokens": 4096,
"container": {
"skills": [
{
"type": "anthropic",
"skill_id": "xlsx",
"version": "latest"
}
]
},
"messages": [{
"role": "user",
"content": "サンプルデータを含む四半期売上追跡スプレッドシートを作成してください"
}],
"tools": [{
"type": "code_execution_20250825",
"name": "code_execution"
}]
}'Word 文書を作成する
response = client.beta.messages.create(
model="claude-sonnet-4-5-20250929",
max_tokens=4096,
betas=["code-execution-2025-08-25", "skills-2025-10-02"],
container={
"skills": [
{
"type": "anthropic",
"skill_id": "docx",
"version": "latest"
}
]
},
messages=[{
"role": "user",
"content": "再生可能エネルギーの利点について 2 ページのレポートを書いてください"
}],
tools=[{
"type": "code_execution_20250825",
"name": "code_execution"
}]
)const response = await client.beta.messages.create({
model: 'claude-sonnet-4-5-20250929',
max_tokens: 4096,
betas: ['code-execution-2025-08-25', 'skills-2025-10-02'],
container: {
skills: [
{
type: 'anthropic',
skill_id: 'docx',
version: 'latest'
}
]
},
messages: [{
role: 'user',
content: '再生可能エネルギーの利点について 2 ページのレポートを書いてください'
}],
tools: [{
type: 'code_execution_20250825',
name: 'code_execution'
}]
});curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: code-execution-2025-08-25,skills-2025-10-02" \
-H "content-type: application/json" \
-d '{
"model": "claude-sonnet-4-5-20250929",
"max_tokens": 4096,
"container": {
"skills": [
{
"type": "anthropic",
"skill_id": "docx",
"version": "latest"
}
]
},
"messages": [{
"role": "user",
"content": "再生可能エネルギーの利点について 2 ページのレポートを書いてください"
}],
"tools": [{
"type": "code_execution_20250825",
"name": "code_execution"
}]
}'PDF を生成する
response = client.beta.messages.create(
model="claude-sonnet-4-5-20250929",
max_tokens=4096,
betas=["code-execution-2025-08-25", "skills-2025-10-02"],
container={
"skills": [
{
"type": "anthropic",
"skill_id": "pdf",
"version": "latest"
}
]
},
messages=[{
"role": "user",
"content": "PDF の請求書テンプレートを生成してください"
}],
tools=[{
"type": "code_execution_20250825",
"name": "code_execution"
}]
)const response = await client.beta.messages.create({
model: 'claude-sonnet-4-5-20250929',
max_tokens: 4096,
betas: ['code-execution-2025-08-25', 'skills-2025-10-02'],
container: {
skills: [
{
type: 'anthropic',
skill_id: 'pdf',
version: 'latest'
}
]
},
messages: [{
role: 'user',
content: 'PDF の請求書テンプレートを生成してください'
}],
tools: [{
type: 'code_execution_20250825',
name: 'code_execution'
}]
});curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: code-execution-2025-08-25,skills-2025-10-02" \
-H "content-type: application/json" \
-d '{
"model": "claude-sonnet-4-5-20250929",
"max_tokens": 4096,
"container": {
"skills": [
{
"type": "anthropic",
"skill_id": "pdf",
"version": "latest"
}
]
},
"messages": [{
"role": "user",
"content": "PDF の請求書テンプレートを生成してください"
}],
"tools": [{
"type": "code_execution_20250825",
"name": "code_execution"
}]
}'次のステップ
事前構築済み Agent Skills を使ったので、次の内容へ進めます。
クロードスキルのドキュメント