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 参数来指定技能

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

相关推荐
黑巧克力可减脂2 小时前
Vibe Coding重构CRM:以AI编程之术,破传统管理之困,承革新致远之道
人工智能·重构·软件工程·ai编程
逻极3 小时前
BMAD之核心架构:为什么“方案化”至关重要 (Phase 3 Solutioning)——必学!BMAD 方法论架构从入门到精通
人工智能·ai·系统架构·ai编程·敏捷开发·ai辅助编程·bmad
用户833525302874 小时前
Tide Commander — 一个用3D战场管理多个AI编程Agent的可视化工具(Claude Code + Codex)
ai编程
yanlele17 小时前
AI Coding 时代下, 关于你会写代码这件事儿, 还重要吗?
前端·javascript·ai编程
NEXT061 天前
2026 技术风向:为什么在 AI 时代,PostgreSQL 彻底成为了全栈工程师的首选数据库
前端·数据库·ai编程
神三元1 天前
我写了个 code-review 的 Agent Skill, 没想到火了
openai·ai编程
开开心心_Every1 天前
剪切板工具存500条,可搜索备份导入导出
linux·运维·服务器·华为od·edge·pdf·华为云
冬奇Lab1 天前
Agent 系统详解:从使用到自定义开发
人工智能·ai编程·claude
御坂10101号1 天前
Total Recall:让 Claude 学会忘记,优化记忆管理
经验分享·vscode·开源·软件工程·ai编程