Agent skill

Claude API

by loulanyue in loulanyue/awesome-claude-notes

Anthropic Claude API 的 Python 和 TypeScript 使用模式。涵盖 Messages API、流式处理、工具使用、视觉功能、扩展思维、批量处理、提示缓存和 Claude Agent SDK。适用于使用 Claude API 或 Anthropic SDK 构建应用程序的场景。

MITAuto-check passedAI & LLM Engineering

Install Claude API

skills CLI
$ npx skills add loulanyue/awesome-claude-notes --skill claude-api -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install loulanyue/awesome-claude-notes claude-api --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/loulanyue/awesome-claude-notes.git skills-src && mkdir -p .claude/skills && cp -r skills-src/docs/zh-CN/skills/claude-api .claude/skills/claude-api && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
claude-api
GitHub stars
272
Used in
1 other repo
Token cost
~1.9k tokens
SKILL.md length
118 words
Files
1
Skills in repo
9
Repo updated
First seen
Licence
MIT

At a glance

Anthropic Claude API 的 Python 和 TypeScript 使用模式。涵盖 Messages API、流式处理、工具使用、视觉功能、扩展思维、批量处理、提示缓存和 Claude Agent SDK。适用于使用 Claude API 或 Anthropic SDK 构建应用程序的场景。

  • Tasks that involve LLM API integration
  • SKILL.md covers 何时激活, 模型选择, Python SDK and TypeScript SDK, plus 11 more sections
  • Calls pip and npm; needs ANTHROPIC_API_KEY

What it does

Claude API is an agent skill from loulanyue/awesome-claude-notes. Anthropic Claude API 的 Python 和 TypeScript 使用模式。涵盖 Messages API、流式处理、工具使用、视觉功能、扩展思维、批量处理、提示缓存和 Claude Agent SDK。适用于使用 Claude API 或 Anthropic SDK 构建应用程序的场景。

Its SKILL.md is about 1.9k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in AI & LLM Engineering, covering LLM API integration. It works with Anthropic API, Claude Agent SDK, Python and TypeScript. The repository describes itself as: Community-maintained distribution of reusable AI coding agents, commands, skills, hooks, and cross-harness workflows. The licence is MIT.

When your agent uses it

  • Tasks that involve LLM API integration

Example prompts

  • “/claude-api”

Requirements

  • Python 3
  • Node.js
  • A credential in ANTHROPIC_API_KEY

What it can do on your machine

Read from SKILL.md and the folder at commit 866b55b. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • pip
    • npm

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use pip and npm, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names these keys or tokens, usually read from environment variables:

    • ANTHROPIC_API_KEY

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Claude API loads about 1.9k tokens when it runs. Until then it costs about 42 tokens; SKILL.md has 118 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~42
When it runs · the whole SKILL.md, loaded when a task matches
~1.9k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from loulanyue/awesome-claude-notes at commit 866b55b, republished under its MIT licence (© loulanyue). 118 words, ~1,950 tokens.

Download SKILL.mdSave it as .claude/skills/claude-api/SKILL.md (or your agent's skills folder).
name
claude-api
description
Anthropic Claude API 的 Python 和 TypeScript 使用模式。涵盖 Messages API、流式处理、工具使用、视觉功能、扩展思维、批量处理、提示缓存和 Claude Agent SDK。适用于使用 Claude API 或 Anthropic SDK 构建应用程序的场景。
source_path
skills/claude-api/SKILL.md
origin
ECC

Claude API

使用 Anthropic Claude API 和 SDK 构建应用程序。

何时激活

  • 构建调用 Claude API 的应用程序
  • 代码导入 anthropic (Python) 或 @anthropic-ai/sdk (TypeScript)
  • 用户询问 Claude API 模式、工具使用、流式传输或视觉功能
  • 使用 Claude Agent SDK 实现智能体工作流
  • 优化 API 成本、令牌使用或延迟

模型选择

模型ID最适合
Opus 4.1claude-opus-4-1复杂推理、架构设计、研究
Sonnet 4claude-sonnet-4-0平衡的编码任务,大多数开发工作
Haiku 3.5claude-3-5-haiku-latest快速响应、高吞吐量、成本敏感型

默认使用 Sonnet 4,除非任务需要深度推理(Opus)或速度/成本优化(Haiku)。对于生产环境,优先使用固定的快照 ID 而非别名。

Python SDK

安装
bash
pip install anthropic
基本消息
python
import anthropic

client = anthropic.Anthropic()  # reads ANTHROPIC_API_KEY from env

message = client.messages.create(
    model="claude-sonnet-4-0",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Explain async/await in Python"}
    ]
)
print(message.content[0].text)
流式传输
python
with client.messages.stream(
    model="claude-sonnet-4-0",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Write a haiku about coding"}]
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)
系统提示词
python
message = client.messages.create(
    model="claude-sonnet-4-0",
    max_tokens=1024,
    system="You are a senior Python developer. Be concise.",
    messages=[{"role": "user", "content": "Review this function"}]
)

TypeScript SDK

安装
bash
npm install @anthropic-ai/sdk
基本消息
typescript
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic(); // reads ANTHROPIC_API_KEY from env

const message = await client.messages.create({
  model: "claude-sonnet-4-0",
  max_tokens: 1024,
  messages: [
    { role: "user", content: "Explain async/await in TypeScript" }
  ],
});
console.log(message.content[0].text);
流式传输
typescript
const stream = client.messages.stream({
  model: "claude-sonnet-4-0",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Write a haiku" }],
});

for await (const event of stream) {
  if (event.type === "content_block_delta" && event.delta.type === "text_delta") {
    process.stdout.write(event.delta.text);
  }
}

工具使用

定义工具并让 Claude 调用它们:

python
tools = [
    {
        "name": "get_weather",
        "description": "Get current weather for a location",
        "input_schema": {
            "type": "object",
            "properties": {
                "location": {"type": "string", "description": "City name"},
                "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
            },
            "required": ["location"]
        }
    }
]

message = client.messages.create(
    model="claude-sonnet-4-0",
    max_tokens=1024,
    tools=tools,
    messages=[{"role": "user", "content": "What's the weather in SF?"}]
)

# Handle tool use response
for block in message.content:
    if block.type == "tool_use":
        # Execute the tool with block.input
        result = get_weather(**block.input)
        # Send result back
        follow_up = client.messages.create(
            model="claude-sonnet-4-0",
            max_tokens=1024,
            tools=tools,
            messages=[
                {"role": "user", "content": "What's the weather in SF?"},
                {"role": "assistant", "content": message.content},
                {"role": "user", "content": [
                    {"type": "tool_result", "tool_use_id": block.id, "content": str(result)}
                ]}
            ]
        )

视觉功能

发送图像进行分析:

python
import base64

with open("diagram.png", "rb") as f:
    image_data = base64.standard_b64encode(f.read()).decode("utf-8")

message = client.messages.create(
    model="claude-sonnet-4-0",
    max_tokens=1024,
    messages=[{
        "role": "user",
        "content": [
            {"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": image_data}},
            {"type": "text", "text": "Describe this diagram"}
        ]
    }]
)

扩展思考

针对复杂推理任务:

python
message = client.messages.create(
    model="claude-sonnet-4-0",
    max_tokens=16000,
    thinking={
        "type": "enabled",
        "budget_tokens": 10000
    },
    messages=[{"role": "user", "content": "Solve this math problem step by step..."}]
)

for block in message.content:
    if block.type == "thinking":
        print(f"Thinking: {block.thinking}")
    elif block.type == "text":
        print(f"Answer: {block.text}")

提示词缓存

缓存大型系统提示词或上下文以降低成本:

python
message = client.messages.create(
    model="claude-sonnet-4-0",
    max_tokens=1024,
    system=[
        {"type": "text", "text": large_system_prompt, "cache_control": {"type": "ephemeral"}}
    ],
    messages=[{"role": "user", "content": "Question about the cached context"}]
)
# Check cache usage
print(f"Cache read: {message.usage.cache_read_input_tokens}")
print(f"Cache creation: {message.usage.cache_creation_input_tokens}")

批量 API

以 50% 的成本降低异步处理大量数据:

python
import time

batch = client.messages.batches.create(
    requests=[
        {
            "custom_id": f"request-{i}",
            "params": {
                "model": "claude-sonnet-4-0",
                "max_tokens": 1024,
                "messages": [{"role": "user", "content": prompt}]
            }
        }
        for i, prompt in enumerate(prompts)
    ]
)

# Poll for completion
while True:
    status = client.messages.batches.retrieve(batch.id)
    if status.processing_status == "ended":
        break
    time.sleep(30)

# Get results
for result in client.messages.batches.results(batch.id):
    print(result.result.message.content[0].text)

Claude Agent SDK

构建多步骤智能体:

python
# Note: Agent SDK API surface may change — check official docs
import anthropic

# Define tools as functions
tools = [{
    "name": "search_codebase",
    "description": "Search the codebase for relevant code",
    "input_schema": {
        "type": "object",
        "properties": {"query": {"type": "string"}},
        "required": ["query"]
    }
}]

# Run an agentic loop with tool use
client = anthropic.Anthropic()
messages = [{"role": "user", "content": "Review the auth module for security issues"}]

while True:
    response = client.messages.create(
        model="claude-sonnet-4-0",
        max_tokens=4096,
        tools=tools,
        messages=messages,
    )
    if response.stop_reason == "end_turn":
        break
    # Handle tool calls and continue the loop
    messages.append({"role": "assistant", "content": response.content})
    # ... execute tools and append tool_result messages

成本优化

策略节省幅度使用时机
提示词缓存缓存令牌成本降低高达 90%重复的系统提示词或上下文
批量 API50%非时间敏感的批量处理
使用 Haiku 而非 Sonnet~75%简单任务、分类、提取
缩短 max_tokens可变已知输出较短时
流式传输无(成本相同)更好的用户体验,价格相同

错误处理

python
import time

from anthropic import APIError, RateLimitError, APIConnectionError

try:
    message = client.messages.create(...)
except RateLimitError:
    # Back off and retry
    time.sleep(60)
except APIConnectionError:
    # Network issue, retry with backoff
    pass
except APIError as e:
    print(f"API error {e.status_code}: {e.message}")

环境设置

bash
# Required
export ANTHROPIC_API_KEY="your-api-key-here"

# Optional: set default model
export ANTHROPIC_MODEL="claude-sonnet-4-0"

切勿硬编码 API 密钥。始终使用环境变量。

原文

导航

© loulanyue, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in docs/zh-CN/skills/claude-api of loulanyue/awesome-claude-notes.

Open the folder on GitHubat commit 866b55b

Used in 1 other repository

We found 1 copy of this SKILL.md (exact, near-identical or edited) in other folders, from 1 other GitHub owner. This page covers the copy in loulanyue/awesome-claude-notes, which our catalogue first saw on October 7, 2026.

Compare with similar skills

Claude API next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Claude API compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Claude API this skillloulanyue/awesome-claude-notes2721 repos~1.9kAutomated safety check: PassMIT
Claude APImajiayu000/claude-skill-registry6663 repos~2.1kAutomated safety check: PassMIT
Claude APIKocoro-lab/Kocoro4148 repos~4.5kAutomated safety check: PassApache-2.0
Claude Cookbooks Reference2025Emma/vibe-coding-cn23k1 repos~2.2kAutomated safety check: PassMIT
Gemini API Devgoogle-gemini/gemini-skills4.3k—~5.1kAutomated safety check: PassApache-2.0
Azure Openai To Responsesmicrosoft/ai-agents-for-beginners77k—~6kAutomated safety check: NotesMIT

Similar skills

  • Claude API

    majiayu000/claude-skill-registry

    Anthropic Claude API patterns for Python and TypeScript. An agent skill from majiayu000/claude-skill-registry.

    666 GitHub starsUsed in 3 repos~2.1k tokens
    AI & LLM EngineeringAuto-check passed
  • Claude API

    Kocoro-lab/Kocoro

    Build apps with the Claude API or Anthropic SDK. An agent skill from Kocoro-lab/Kocoro.

    414 GitHub starsUsed in 8 repos~4.5k tokens
    AI & LLM EngineeringAuto-check passed
  • Claude Cookbooks Reference

    2025Emma/vibe-coding-cn

    Reference of Claude API examples and guides covering tool use, vision, RAG, classification, summarization, text-to-SQL, prompt caching and agent patterns.

    23k GitHub starsUsed in 1 repo~2.2k tokens
    AI & LLM EngineeringAuto-check passed
  • Gemini API Dev

    google-gemini/gemini-skills

    Official

    A skill your agent uses when writing code that calls the Gemini API for text generation, multi-turn chat, multimodal understanding, image generation, video generation, speech generation (TTS), voice…

    4.3k GitHub stars~5.1k tokensUpdated yesterday
    AI & LLM EngineeringAuto-check passed
  • Azure Openai To Responses

    microsoft/ai-agents-for-beginners

    Official

    Migrate Python apps from Azure OpenAI Chat Completions to the Responses API.

    77k GitHub stars~6k tokensUpdated 18 days ago
    AI & LLM EngineeringAuto-check: notes
  • Gemini API Dev

    Ayuilos/Miffan

    A skill your agent uses when building applications with Gemini API hosted models, including Gemini and Gemma 4, working with multimodal content (text, images, audio, video), implementing function…

    182 GitHub starsUsed in 1 repo~1.4k tokens
    AI & LLM EngineeringAuto-check passed

More from loulanyue/awesome-claude-notes

All 9 skills in this repo
  • Team Builder

    loulanyue/awesome-claude-notes

    Interactive agent picker for composing and dispatching parallel teams

    272 GitHub starsUsed in 3 repos~1.6k tokens
    Auto-check passed
  • Claude Devfleet

    loulanyue/awesome-claude-notes

    Orchestrate multi-agent coding tasks via Claude DevFleet — plan projects, dispatch parallel agents in isolated worktrees, monitor progress, and read structured reports.

    272 GitHub starsUsed in 2 repos~1.4k tokens
    Auto-check passed
  • Configure Ecc

    loulanyue/awesome-claude-notes

    Interactive installer for awesome claude notes — guides users through selecting and installing skills and rules to user-level or project-level directories, verifies paths, and optionally optimizes…

    272 GitHub starsUsed in 2 repos~3.9k tokens
    Auto-check passed
  • Configure Ecc

    loulanyue/awesome-claude-notes

    awesome claude notes のインタラクティブなインストーラー — スキルとルールの選択とインストールをユーザーレベルまたはプロジェクトレベルのディレクトリへガイドし、パスを検証し、必要に応じてインストールされたファイルを最適化します。

    272 GitHub stars~2.2k tokensUpdated 2 days ago
    Auto-check passed
  • Configure Ecc

    loulanyue/awesome-claude-notes

    awesome claude notes 的交互式安装程序 — 引导用户选择并安装技能和规则到用户级或项目级目录,验证路径,并可选择优化已安装文件。

    272 GitHub stars~2.3k tokensUpdated 2 days ago
    Auto-check passed
  • Project Guidelines Example

    loulanyue/awesome-claude-notes

    실제 프로덕션 애플리케이션을 기반으로 한 프로젝트별 스킬 템플릿 예시.

    272 GitHub starsUsed in 1 repo~2k tokens
    Auto-check: notes

Questions about Claude API

What does Claude API do?

Anthropic Claude API 的 Python 和 TypeScript 使用模式。涵盖 Messages API、流式处理、工具使用、视觉功能、扩展思维、批量处理、提示缓存和 Claude Agent SDK。适用于使用 Claude API 或 Anthropic SDK 构建应用程序的场景。. Claude API is an agent skill from loulanyue/awesome-claude-notes.

When should I use Claude API?

Claude API fits situations like: tasks that involve LLM API integration.

How do I install Claude API in Claude Code?

Run `npx skills add loulanyue/awesome-claude-notes --skill claude-api -a claude-code`. Or copy the skill folder (docs/zh-CN/skills/claude-api in loulanyue/awesome-claude-notes) into .claude/skills/claude-api in your project. Claude Code loads it when a task matches its description.

How do I install Claude API in Codex?

Run `npx skills add loulanyue/awesome-claude-notes --skill claude-api -a codex`. Or copy the skill folder (docs/zh-CN/skills/claude-api in loulanyue/awesome-claude-notes) into .agents/skills/claude-api in your project. Codex loads it when a task matches its description.

Can I use Claude API in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add loulanyue/awesome-claude-notes --skill claude-api -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/claude-api, .gemini/skills/claude-api, .github/skills/claude-api and .opencode/skills/claude-api in your project.

What does Claude API need to run?

Going by SKILL.md and its folder, Claude API needs the command-line tools its instructions call (pip and npm) and credentials named ANTHROPIC_API_KEY. Our summary lists: Python 3; Node.js; A credential in ANTHROPIC_API_KEY.

Does Claude API access the network?

SKILL.md contains no URLs. Its commands use pip and npm, which can reach the network depending on how they are called. This is read from the text; nothing was executed.

Is Claude API safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Claude API use?

Claude API is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Claude API use?

About 1.9k tokens (SKILL.md is roughly 7.8k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Claude API?

Skills that share tags, products or a category with Claude API: Claude API (majiayu000/claude-skill-registry, 666 stars), Claude API (Kocoro-lab/Kocoro, 414 stars), Claude Cookbooks Reference (2025Emma/vibe-coding-cn, 23k stars) and Gemini API Dev (google-gemini/gemini-skills, 4.3k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Claude API?

loulanyue (a GitHub user) maintains it in loulanyue/awesome-claude-notes, which has 272 GitHub stars. The repository holds 9 skills in this directory. The repository was last updated on October 5, 2026.

Source: loulanyue/awesome-claude-notes on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.