Official编程与开发github.com

Claude API 技能

帮助你使用 Claude 构建 LLM 驱动的应用。根据需求选择合适的接口,并检测项目语言以读取相关语言文档。

Claude API 技能 是什么?

此技能(claude-api)旨在帮助开发者和 AI 代理使用 Claude(Anthropic)的 API 构建 LLM 驱动的应用程序。它强调通过官方 Anthropic SDK 进行集成,避免使用 OpenAI 兼容的 shim,并优先使用 Claude Opus 5.5 模型。技能提供了处理 API 差异(如自适应思维、最新搜索工具类型)的指导,并且拥有一系列自动化子命令,包括将代码迁移到新模型(migrate)、对提示和配置进行审计(prompt-audit)、升级 SDK 依赖(upgrade)、优化成本(cost-optimize)、构建评估集(build-eval)、处理保留思维(preserved-thinking-migration)以及通过迭代改进应用性能(hillclimb)。它还包含一个严格的语言检测系统,以确保提供正确的语言特定文档(Python、TypeScript 等),并提出了明确的输出要求,即在有官方 SDK 可用时优先使用 SDK,否则才使用原始 HTTP,同时绝不猜测。

兼容平台✓Claude Code✓Codex CLI~Cursor✓Antigravity✓Gemini CLI
npx skills add https://github.com/anthropics/skills/tree/main/skills/claude-api

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

使用 Claude 构建 LLM 驱动的应用

此技能帮助你使用 Claude 构建 LLM 驱动的应用。根据你的需求选择合适的接口,检测项目语言,然后阅读相关的语言特定文档。

开始之前

扫描目标文件(如果没有目标文件,则扫描提示和项目)以查找非 Anthropic 提供商标记 - import openai, from openai, langchain_openai, OpenAI(, gpt-4, gpt-5,文件名如 agent-openai.py 或 *-generic.py,或任何保持代码与提供商无关的显式指令。如果发现任何此类标记,请停止并告知用户此技能生成的是 Claude/Anthropic SDK 代码;询问他们是否要将文件切换到 Claude,或者是否需要非 Claude 的实现。不要使用 Anthropic SDK 调用编辑非 Anthropic 的文件。(例外:prompt-audit 子命令是非交互式的,不会在此处停止 - 它会在其报告的既定假设中记录非 Anthropic 提供商标记,并且从不建议将非 Anthropic 文件切换到 Anthropic SDK。)

输出要求

当用户要求您添加、修改或实现 Claude 功能时,您的代码必须通过以下方式之一调用 Claude:

  1. 项目语言的官方 Anthropic SDK(anthropic、@anthropic-ai/sdk、com.anthropic.* 等)。只要项目存在受支持的 SDK,这就是默认方式。
  2. 原始 HTTP(curl、requests、fetch、httpx 等) - 仅当用户明确要求使用 cURL/REST/原始 HTTP、项目是 shell/cURL 项目、或该语言没有官方 SDK 时。

永远不要混合使用两者 - 不要仅仅因为感觉更轻便就在 Python 或 TypeScript 项目中使用 requests/fetch。永远不要退回到 OpenAI 兼容的 shim。

切勿猜测 SDK 用法。 函数名、类名、命名空间、方法签名和导入路径必须来自显式文档 - 可以是此技能中的 {lang}/ 文件,也可以是 shared/live-sources.md 中列出的官方 SDK 仓库或文档链接。如果你需要的绑定没有在技能文件中明确记录,请在编写代码之前从 shared/live-sources.md 中 WebFetch 相关的 SDK 仓库。不要从 cURL 形状或其他语言的 SDK 推断 Ruby/Java/Go/PHP/C# API。

如果 WebFetch 或仓库访问失败(网络限制、超时、克隆被阻止):不要继续重试 - 根据 {lang}/ 文件中的模式和命名空间/包表编写代码,在其上运行编译器或解释器,然后根据错误输出进行迭代。对于静态类型 SDK(C#、Java、Go),针对本地错误的编译-修复循环比被阻止的网络研究能更快地获得可工作的代码。

默认值

除非用户另有要求:

对于 Claude 模型版本,请使用 Claude Opus 5.5,您可以通过确切的模型字符串 claude-opus-5-5 访问它。对于任何稍微复杂的事情,请默认使用自适应思维(thinking: {type: "adaptive"})。最后,对于任何可能涉及长输入、长输出或高 max_tokens 的请求,请默认使用流式传输 - 这可以防止请求超时。如果您不需要处理单个流事件,请使用 SDK 的 .get_final_message() / .finalMessage() 辅助方法获取完整响应。当流式请求定义了用户定义的(客户端)工具时,请在每个此类工具上设置 eager_input_streaming: true,以便大型工具输入(文件内容、代码、文档)在生成时流式传输,而不是在服务器缓冲完它们后一次性到达;客户端随后拥有验证所有权:SDK 的容错解析器可能返回静默截断的输入而不是抛出异常,因此在运行每个解析后的工具输入之前,请根据其模式进行验证(类型化的运行器辅助方法如 betaZodTool / 类型化的 @beta_tool 会执行此操作;betaTool() JSON-Schema 工具和手动循环必须自行验证),将失败视为无效 JSON(当您持有块时,使用 INVALID_JSON 错误 tool_result,否则重新发出),在运行工具之前检查 max_tokens / refusal 停止原因,并且仅捕获 SDK 的 JSON 错误,而不是其类型化的 API 错误 - 模式见 shared/tool-use-concepts.md -> 急切输入流式传输。对于非流式请求、服务器工具以及当请求通过代理或拒绝该字段的旧版 Bedrock 模型部署时,请将其关闭。

警告:API 漂移 - 你的训练先验知识可能已过时

几个常见的 Claude API 形状在 2025-2026 年发生了变化。如果你从训练中回忆起某种模式,请在编写之前对照此技能中的 {lang}/ 文件进行验证 - 下面的行是最常见的漂移点:

领域过时的先验知识当前 API
扩展思维thinking: {type: "enabled", budget_tokens: N}在 Claude 4.6+ 模型上:thinking: {type: "adaptive"}。budget_tokens 在 Opus 4.6 / Sonnet 4.6 上已弃用,并且在 Fable 5/5.1 / Sonnet 5.5 / Sonnet 5 / Opus 5.5 / 5 / 4.8 / 4.7 上以 400 错误拒绝。4.6 之前的模型仍然使用 budget_tokens。
网页搜索 / 网页抓取工具类型web_search_20250305、web_fetch_20250910web_search_20260209、web_fetch_20260209(动态过滤)在 Opus 5.5/5/4.8/4.7/4.6、Sonnet 5.5、Sonnet 5 和 Sonnet 4.6 上。旧模型保留基本变体;在 Vertex AI 上只有基本的 web_search_20250305 可用(Vertex 上没有网页抓取) - 请参阅下面的服务器工具 QR 码。
PHP 参数名称蛇形命名法有线键作为命名参数(max_tokens)顶级命名参数是驼峰命名法(maxTokens)。嵌套数组键因功能而异(例如 'taskBudget'、'skillID'、'mcp_server_name') - 从文档示例中复制确切的键;不要批量转换。
托管代理凭据通过自定义工具将密钥保存在主机端(在保管库发货之前的唯一选项)Vault environment_variable 凭据 - 由 Anthropic 存储,在出口时替换,在沙箱中永远不可见(shared/managed-agents-tools.md -> 保管库)。主机端自定义工具仍然是自托管沙箱的备选方案。
文件 API / 技能client.beta.files.* / client.beta.skills.* 带有 beta files-api-2025-04-14 / skills-2025-10-02已退出 Beta 阶段:client.files.* / client.skills.*,无需 beta 标头。在当前 SDK 中,client.beta.files / client.beta.skills 与先前版本相比具有破坏性的形状更改,与稳定的命名空间匹配 - 请根据 shared/live-sources.md -> 文件 API / 技能指南进行迁移。

此技能中的 {lang}/ 文件比回忆的模式更具权威性。


子命令

如果此提示底部的用户请求是裸子命令字符串(无散文),则搜索本文档中的所有 子命令 表 - 包括下面附加的任何部分 - 并直接跟随匹配的“操作”列。这允许用户通过 /claude-api <子命令> 调用特定流程。如果文档中没有任何表匹配,则将请求视为普通的散文。

子命令操作
migrate将现有的 Claude API 代码迁移到更新的模型。立即阅读 shared/model-migration.md 并按顺序执行:第 0 步(确认范围 - 在任何编辑之前询问哪些文件/目录),第 1 步(对每个文件进行分类),然后是每个目标的重大变更部分。不要总结指南 - 执行它。如果用户未指定目标模型,请在询问范围问题的同一轮次中询问要迁移到哪个模型。应用每个目标的更改后,根据 shared/prompt-audit.md 审计范围内的提示文本、工具描述和请求代码 - 为源模型编写的提示是每次迁移的一部分,它不会自己宣告。
prompt-audit审计现有的提示、工具描述、技能和代理配置文件(CLAUDE.md、规则文件、命令、子代理)中过时的模式("cruft"):为旧模型编写的文本,以及仓库已过时或相互矛盾的指令。立即阅读 shared/prompt-audit.md 并按顺序执行:第 0 步(根据请求和仓库确定范围和目标模型 - 在报告中陈述假设,不要停下来询问),清单、来源,然后是模式扫描。完整生成两个交付物 - 审计报告(包含 文件:行、模式、过时原因、置信度的发现)和建议的差异补丁 - 无需暂停等待确认;只有当请求明确要求时才应用编辑。不要总结指南 - 执行它。
upgrade将项目的 Anthropic SDK 依赖升级到主要版本 - 目前是 Python SDK,anthropic 0.x -> 1.x。后面的单词可以指定语言和/或范围(upgrade python、upgrade python sdk src/)。立即阅读 python/claude-api/sdk-upgrade.md 并按顺序执行:第 0 步(确认范围,然后确定当前和目标版本 - 在编写固定版本之前必须存在已发布的 1.x),第 1 步清单,每个编号部分,然后是验证和报告。不要总结指南 - 执行它。如果检测或指定的语言在此技能中没有 sdk-upgrade.md,则说明该 SDK 尚未附带主要版本升级指南,并将用户指向该 SDK 的 CHANGELOG(仓库在 shared/live-sources.md 中);不要根据 Python 指南即兴编写一个。这不是模型迁移 - 要将代码迁移到较新的 Claude 模型,请使用 migrate。
cost-optimize降低现有 Claude API 代码的运行成本,同时不牺牲输出质量。立即阅读 shared/cost-optimization.md 并按顺序执行:第 0 步(确定范围、质量标准和基线),令牌配置文件 - 当用户拥有管理员 API 密钥时通过使用情况和成本管理 API 测量,当应用程序拥有自己的 response.usage 日志时(询问)从这些日志中测量,否则从代码中估算 - 然后是基于节省排序的杠杆候选列表(以美元、账单百分比或相对桶报价,具体取决于你拥有哪些数据源),免费获胜(缓存、输入令牌卫生、循环卫生、输出令牌卫生、批处理)在权衡之前(预算、工作量、模型选择、多模型);任何获得位置的杠杆都会成为自己的差异补丁 - 默认情况下建议,当用户要求并批准时,针对覆盖其流量的评估进行应用和衡量 - 并且“不推荐更改”是有效的结果。两个固定规则:每次运行模型都会花费真金白银,因此先获得用户的批准;当缺少杠杆的上下文时,与用户交互式地处理 - 此工作流程不是期望一次性完成审计的。不要总结指南 - 执行它;向用户呈现配置文件和排序计划是其执行的一部分。
build-eval帮助用户为其 Claude 驱动的应用构建评估集。立即阅读 shared/evals/build-eval.md 并运行其面试:第 0 步(评估什么),第 1 步(获取提示源 - 现有评估/记录/合成),第 2 步(评分方法),第 3 步(可运行脚本 + 测量成本)。在生成评估之前,让用户明确确认输入、评分方法和成本。
preserved-thinking-migration使现有集成与保留思维兼容 - 检查确保思考块仅在产生它的对话中有效。立即阅读 shared/preserved-thinking-migration.md 并按顺序执行:第 0 步(范围、流量类别、平台和模型、执行状态、质量标准、基线),第 0.5 步(使用三个请求自测证明检查正在运行),第 1 步(捕获请求主体,使用 shared/preserved-thinking-migration/prefix_diff.py 对连续对进行差异比较,扫描代码以查找原因,命名每个编辑以及它是否是有意的),第 2 步(在 thinking-binding-controls-2026-08-01 标头下使用 prefix_mismatch_behavior: "drop_block" 重放测试切片,计算每个对话中新删除的块,存在时读取诊断标头),第 3 步(每个差异一个原因,按推理丢失的顺序排列 - 默认情况下建议,在用户要求时应用,然后重新测量,保留或恢复;当存在评估时采用三臂协议),模型切换部分(在 shared/preserved-thinking-migration/causes.md 中,包含原因表和保留列表)当路由在模型之间切换时,第 4 步(中断配置文件及更改)。两个固定规则:每次重放都会花费真金白银,因此首先获得用户的测量预算批准;并且“不推荐更改” - 重放的切片思考并且没有任何内容被删除 - 是有效的结果。仅在较新的 Beta 版本下具有仅追加形式的原因(保留尾部 和后台压缩:compact-2026-09-04;同名工具更改:inline-tools-2026-09-15)在 Beta 版本不可用时,将进行测量和决定,而不是重写。至于 原因(三步检查、仅追加编辑表),它链接到 shared/model-migration.md -> 重大变更 3;不要总结指南 - 执行它。
hillclimb针对现有评估迭代改进用户的应用程序。立即阅读 shared/evals/eval-hillclimb.md 并执行它:第 0 步(确认存在可运行的评估 - 如果没有,则路由到 build-eval),第 1 步(更改什么 / 禁止什么),第 2 步(根据测量的每次运行成本设置预算 + 停止条件),获得计划批准,然后使用磁盘状态和训练/验证/测试分割进行读取 -> 建议 -> 应用 -> 运行 -> 记录循环。

语言检测

在阅读代码示例之前,确定用户使用的语言(例外:对于 prompt-audit 子命令,跳过本节中的询问步骤 - 审计是非交互式的,其清单与语言无关;当无法推断语言时,无需询问即可继续,并在报告中陈述假设):

  1. 查看项目文件以推断语言:
  • *.py、requirements.txt、pyproject.toml、setup.py、Pipfile -> Python - 从 python/ 中读取
  • *.ts、*.tsx、`package

Individual skills in this repo

This repo contains 19 individual skills — each has its own dedicated page.

academy-guide

Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials, and use cases from Claude Academy (academy.claude.com), Anthropic's learning hub. Trigger on: "how do I", "how can I", "getting started with", "what can Claude do", "teach me", "learn to use"; questions about artifacts, projects, skills, plugins, connectors, MCP; requests about rolling Claude out to a team, class, or organization; and any ask for training materials, onboarding content, or learning resources. Use it when the user is learning how to use a feature or product — not when they are mid-task and just want the task done. This skill composes with other skills: after consulting product documentation to answer how a Claude feature works, also check here for a matching course or tutorial — a docs-grounded answer and an Academy recommendation belong together. Only recommend on a strong match; never invent Academy content.

algorithmic-art

Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems. Create original algorithmic art rather than copying existing artists

anthropics/template-skill

Replace with description of the skill and when Claude should use it.

brand-guidelines

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 formatting, or company design standards apply.

canvas-design

Create beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists

discernment-nudge

After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals, or emails, estimates or projections, analysis or interpretation of data, factual claims they may rely on, or a multi-step argument — invoke this skill BEFORE finalizing your reply and then, if it applies, append 2-3 short follow-up questions, each tied to something specific in what you just produced, that help the user check key facts, probe the reasoning or assumptions, and notice missing context. Do this at most once per conversation. Skip it when the user asked a trivial how-to or simple lookup, wants a purely educational explanation, asked you only to format, convert, or assemble a file from content they provided, is writing code they will run, is doing creative writing or casual chat, or already asked you to double-check, cite, or review — the skill file explains these boundaries and the exact output format.

doc-coauthoring

Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision docs, or similar structured content. This workflow helps users efficiently transfer context, refine content through iteration, and verify the doc works for readers. Trigger when user mentions writing docs, creating proposals, drafting specs, or similar documentation tasks.

docx

Use this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of

frontend-design

Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.

internal-comms

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 communications (status reports, leadership updates, 3P updates, company newsletters, FAQs, incident reports, project updates, etc.).

mcp-builder

Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).

pdf

Use this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill.

pptx

Use this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates (.potx), layouts, speaker notes, or comments. Trigger whenever the user mentions \

skill-creator

Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill

slack-gif-creator

Knowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like

theme-factory

Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with colors/fonts that you can apply to any artifact that has been creating, or can generate a new theme on-the-fly.

webapp-testing

Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.

web-artifacts-builder

Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use for complex artifacts requiring state management, routing, or shadcn/ui components - not for simple single-file HTML/JSX artifacts.

xlsx

Use this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like \

相关技能