Skills2026年3月29日·1 分钟阅读

Claude Official Skill: claude-api

Build apps with the Claude API or Anthropic SDK. TRIGGER when: code imports `anthropic`/`@anthropic-ai/sdk`/`claude_agent_sdk`, or user asks to use Claude API, Anthropic SDKs, o...

Agent 就绪

先审查再安装

这个资产需要先审查。复制的指令会要求 Agent dry-run、列出写入项,确认后再继续。

Needs Confirmation · 64/100策略:需确认
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Community
入口
Claude Official Skill: claude-api
先审查命令
npx -y tokrepo@latest install 2be86b66-71f9-49bc-ae43-fdba086f79ea --target codex

先 dry-run,确认写入项后再运行此命令。

TL;DR
Official skill that guides Claude Code through building apps with the Claude API, SDKs, and agent patterns.
§01

What it is

The claude-api skill is an official Claude Code skill maintained by Anthropic. It activates automatically when your code imports anthropic, @anthropic-ai/sdk, or claude_agent_sdk, and provides Claude Code with the knowledge to build LLM-powered applications correctly. The skill covers prompt caching, streaming, tool use, vision, and the managed agents API.

This skill targets developers building production applications on the Claude API who want Claude Code to generate correct, idiomatic SDK code rather than guessing at API shapes.

§02

How it saves time or tokens

Without this skill, Claude Code may generate outdated or incorrect API calls for Anthropic-specific features like prompt caching or extended thinking. The skill injects current API patterns so generated code works on first run. It also teaches Claude Code to use prompt caching by default, which can reduce token costs by up to 90% for repeated prefixes.

§03

How to use

  1. Install the skill in Claude Code:
claude skill install anthropics/skills/claude-api
  1. Or manually place the skill file:
mkdir -p .claude/skills/claude-api
# Copy SKILL.md content to .claude/skills/claude-api/SKILL.md
  1. Start coding with the Claude API -- the skill activates automatically:
import anthropic

client = anthropic.Anthropic()
message = client.messages.create(
    model='claude-sonnet-4-20250514',
    max_tokens=1024,
    messages=[{'role': 'user', 'content': 'Hello'}]
)
print(message.content[0].text)
§04

Example

import anthropic

client = anthropic.Anthropic()

# Streaming with tool use
with client.messages.stream(
    model='claude-sonnet-4-20250514',
    max_tokens=1024,
    tools=[{
        'name': 'get_weather',
        'description': 'Get current weather for a city',
        'input_schema': {
            'type': 'object',
            'properties': {
                'city': {'type': 'string'}
            },
            'required': ['city']
        }
    }],
    messages=[{'role': 'user', 'content': 'Weather in Tokyo?'}]
) as stream:
    for text in stream.text_stream:
        print(text, end='', flush=True)
§05

Related on TokRepo

§06

Common pitfalls

  • Forgetting to set the ANTHROPIC_API_KEY environment variable before running -- the SDK throws a generic error that does not clearly indicate the missing key
  • Using an outdated model identifier; always check the current model names in the Anthropic docs as they change with new releases
  • Not enabling prompt caching for repeated system prompts, which wastes tokens on every request

常见问题

How does the claude-api skill activate?+

The skill triggers automatically when Claude Code detects imports of anthropic, @anthropic-ai/sdk, or claude_agent_sdk in your codebase. You can also invoke it manually. Once active, it provides Claude Code with current API patterns, model names, and best practices.

Does this skill work with TypeScript?+

Yes. The skill covers both the Python SDK (anthropic) and the TypeScript SDK (@anthropic-ai/sdk). It detects your project language and provides the appropriate code patterns and import styles.

What is prompt caching and why does the skill enable it?+

Prompt caching lets you mark portions of your prompt as cacheable. The API stores these portions and reuses them across requests, reducing input token costs by up to 90% for repeated system prompts or context. The skill teaches Claude Code to use cache_control blocks by default.

Can this skill help build multi-agent systems?+

Yes. The skill includes knowledge of the Claude Agent SDK and managed agents API. It covers patterns for tool handoffs, agent orchestration, and the TeammateTool interface for multi-agent coordination.

Is this skill maintained by Anthropic?+

Yes. The claude-api skill is from the official anthropics/skills repository on GitHub, maintained by the Claude Code team. It is updated as the API evolves to reflect current model names, parameters, and features.

引用来源 (3)
🙏

来源与感谢

Created by Anthropic. Licensed under MIT. anthropics/skills

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产