Claude Code中英文系列教程35:通过API使用Skills创建ppt,word文档和pdf

Learn how to use Agent Skills to create documents with the Claude API in under 10 minutes.

如何在 10 分钟内 通过 Claude API 使用Agent Skills 创建文档。

This tutorial shows you how to use Agent Skills to create a PowerPoint presentation. You'll learn how to enable Skills, make a simple request, and access the generated file.

本教程将向你展示如何使用Agent Skills创建 PowerPoint 演示文稿。你将学习如何启用技能、发起简单请求以及访问生成的文件。

Prerequisites 前提条件

Anthropic API key //Anthropic API 密钥

Python 3.7+ or curl installed

Basic familiarity with making API requests 对 API 请求有基本的了解

What are Agent Skills? 什么是代理技能?

Pre-built Agent Skills extend Claude's capabilities with specialized expertise for tasks like creating documents, analyzing data, and processing files. Anthropic provides the following pre-built Agent Skills in the API:

预构建的代理技能通过为创建文档、分析数据和处理文件等任务提供专业专长来扩展 Claude 的功能。Anthropic 在 API 中提供了以下预构建的代理技能:

PowerPoint (pptx): Create and edit presentations 创建和编辑演示文稿

Excel (xlsx): Create and analyze spreadsheets 创建和分析电子表格

Word (docx): Create and edit documents 创建和编辑文档

PDF (pdf): Generate PDF documents 生成 PDF 文档

Step 1: List available Skills 列出可用技能

First, let's see what Skills are available. We'll use the Skills API to list all Anthropic-managed Skills:

首先,让我们看看有哪些技能可用。我们将使用技能 API 来列出所有 Anthropic 管理的技能:

```bash

import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic();

// List Anthropic-managed 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}`);

}

```

You see the following Skills: pptx, xlsx, docx, and pdf.

你可以看到以下技能: pptx , xlsx , docx 和 pdf 。

This API returns each Skill's metadata: its name and description. Claude loads this metadata at startup to know what Skills are available. This is the first level of progressive disclosure, where Claude discovers Skills without loading their full instructions yet.

该 API 返回每个技能的元数据:其名称和描述。Claude 在启动时加载此元数据以了解有哪些技能可用。这是渐进式披露的第一层,Claude 在加载技能的完整指令之前就发现了技能。

Step 2\:Create a presentation 第二步:创建演示文稿

Now we'll use the PowerPoint Skill to create a presentation about renewable energy. We specify Skills using the container parameter in the Messages API:

现在我们将使用 PowerPoint 技能来创建一个关于可再生能源的演示文稿。我们使用 Messages API 中的 container 参数来指定技能:

```bash

import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic();

// Create a message with the PowerPoint Skill

const response = await client.beta.messages.create({

model: "claude-opus-4-6",

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: "Create a presentation about renewable energy with 5 slides"

}],

tools: [{

type: "code_execution_20250825",

name: "code_execution"

}]

});

console.log(response.content);

```

其中

container.skills: Specifies which Skills Claude can use 指定 Claude 可以使用的技能

type: "anthropic": Indicates this is an Anthropic-managed Skill 表示这是一个由 Anthropic 管理的技能

skill\_id: "pptx": The PowerPoint Skill identifier PowerPoint 技能标识符

version: "latest": The Skill version set to the most recently published 技能版本设置为最新发布版本

tools: Enables code execution (required for Skills) 启用代码执行(技能所必需的)

Beta headers: code-execution-2025-08-25 and skills-2025-10-02

When you make this request, Claude automatically matches your task to the relevant Skill. Since you asked for a presentation, Claude determines the PowerPoint Skill is relevant and loads its full instructions: the second level of progressive disclosure. Then Claude executes the Skill's code to create your presentation.

当你发起这个请求时,Claude 会自动将你的任务匹配到相关的技能。因为你要求制作演示文稿,Claude 确定 PowerPoint 技能是相关的,并加载其完整指令:渐进式披露的第二层。然后 Claude 执行技能的代码来创建你的演示文稿。

Step 3: Download the created file下载创建的文件

The presentation was created in the code execution container and saved as a file. The response includes a file reference with a file ID. Extract the file ID and download it using the Files API:

演示文稿在代码执行容器中创建并保存为文件。响应中包含一个文件引用,其中包含文件 ID。提取文件 ID 并使用 Files API 下载它:

```bash

// Extract file ID from response

let fileId: string | null = null;

for (const block of response.content) {

if (block.type === "tool_use" && block.name === "code_execution") {

// File ID is in the tool result

for (const resultBlock of block.content) {

if ("file_id" in resultBlock) {

fileId = resultBlock.file_id;

break;

}

}

}

}

if (fileId) {

// Download the file

const fileContent = await client.beta.files.download(fileId, {

betas: ["files-api-2025-04-14"]

});

// Save to disk

const fs = require("fs/promises");

await fs.writeFile("renewable_energy.pptx", Buffer.from(await fileContent.arrayBuffer()));

console.log("Presentation saved to renewable_energy.pptx");

}

```

Try more examples 尝试更多示例

Now that you've created your first document with Skills, try these variations:

现在你已经使用 Skills 创建了第一个文档,请尝试这些变体:

Create a spreadsheet 创建电子表格

```bash

const response = await client.beta.messages.create({

model: "claude-opus-4-6",

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: "Create a quarterly sales tracking spreadsheet with sample data" 创建一个包含示例数据的季度销售跟踪电子表格

}],

tools: [{

type: "code_execution_20250825",

name: "code_execution"

}]

});

```

Create a Word document 创建 Word 文档

```bash

const response = await client.beta.messages.create({

model: "claude-opus-4-6",

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: "Write a 2-page report on the benefits of renewable energy"撰写一份关于可再生能源好处的两页报告

}],

tools: [{

type: "code_execution_20250825",

name: "code_execution"

}]

});

```

Generate a PDF 生成 PDF

```bash

const response = await client.beta.messages.create({

model: "claude-opus-4-6",

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: "Generate a PDF invoice template"生成PDF发票模板

}],

tools: [{

type: "code_execution_20250825",

name: "code_execution"

}]

});

```

小结:

Messages API 中的 container 参数来指定技能

演示文稿在代码执行容器中创建

相关推荐
Java后端的Ai之路11 小时前
CodeBuddy-Rules配置
人工智能·python·ai编程
阿Q十四12 小时前
老板怎么带团队?从 Claude Code 源码学 Multi-Agent 的“派活”艺术
ai编程
名不经传的养虾人12 小时前
从0到1:企业级AI项目迭代日记 Vol.26|用AI是借力,教AI才是复制自己
人工智能·ai编程·skill·教ai复制自己
ZengLiangYi12 小时前
Cursor 对话导入:解析 SQLite 里的宝藏
ai编程·cursor
阿耶同学12 小时前
🔥 CrewAI 实战:构建多 Agent 协作团队
ai编程
GarrettGao12 小时前
MCP 实践-用 AI 对话触发 Jenkins 打包App
ai编程·mcp
郭煌12 小时前
# 什么该交给 AI,什么自己来:一个工程师的 4 象限决策法
ai编程
ZengLiangYi12 小时前
AI Coding JSONL 里的系统标签噪音如何过滤
ai编程
HLAIA光子12 小时前
Claude Code、Codex 为什么都选了 Grep 而不是 RAG
ai编程·claude
沫离痕13 小时前
Claude Code 配置目录说明
ai编程