← 返回 Skills 市场
simonpierreboucher02

anthropic api

作者 Simon-Pierrre Boucher · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ 安全检测通过
49
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install anthropic-api-al
功能描述
Integrate with Anthropic Claude API to generate chat, tool use, vision, document analysis, and coding responses while controlling cost and handling errors.
使用说明 (SKILL.md)

Anthropic (Claude) API Skill

Use this skill to call the Anthropic Claude API correctly, safely, and cost-consciously through the Anthropic MCP server's four tools.


1. Name

anthropic-claude-api — Anthropic (Claude) API operations skill.

2. Purpose

Give an agent the judgment to use Claude well: choose the right model, set required parameters, run tool-use loops, handle vision/documents, enable extended thinking and prompt caching when worthwhile, control cost, and handle errors. The skill pairs with the Anthropic MCP server (tools: anthropic_messages, anthropic_count_tokens, anthropic_models, anthropic_request).

3. When to use Claude

Use Claude for:

  • Chat / assistants — conversational responses, Q&A.
  • Agents — multi-step reasoning with tool use.
  • Tool use / function calling — let the model invoke your functions.
  • Vision — analyze images (charts, screenshots, photos).
  • Long-context — read long documents/PDFs and reason over them.
  • Coding — generate, review, refactor, explain code.

4. When NOT to use Claude

  • Embeddings / vector search — the Anthropic API does not provide an embeddings endpoint; use a dedicated embeddings provider.
  • Web search / live browsing — use a search API or the appropriate web tool, not the Messages endpoint.
  • Deterministic non-LLM compute — don't pay for the model to do arithmetic or string ops a script can do.

5. Environment

  • ANTHROPIC_API_KEYrequired; sent as x-api-key. Never expose it.
  • anthropic-version header — required (default 2023-06-01); the MCP server sends it.
  • Optional: ANTHROPIC_BETA (beta features), ANTHROPIC_API_BASE_URL, ANTHROPIC_TIMEOUT_MS, ANTHROPIC_MAX_RETRIES, LOG_LEVEL.

6. Operations (4 tools)

Tool Use it to
anthropic_messages Generate responses: chat, tool use, vision, documents, thinking. max_tokens required.
anthropic_count_tokens Estimate input tokens before paying for generation.
anthropic_models List/inspect available models.
anthropic_request Call any other endpoint (batches, files, beta).

7. Model selection

Pick the cheapest model that meets quality needs:

  • claude-opus-4-8most capable; hard reasoning, complex agents, deep coding.
  • claude-sonnet-4-6balanced; most production work.
  • claude-haiku-4-5fast & cheap; classification, extraction, routing, high volume. Default here.

Start with Haiku; escalate to Sonnet, then Opus, only when quality demands it. See reference/models.md.

8. Messages workflow

  1. Choose a model.
  2. Set max_tokens (required; also your output cost cap).
  3. Add a system prompt for role/constraints.
  4. Pass full conversation history in messages (the API is stateless).
  5. Read stop_reason (end_turn, max_tokens, stop_sequence, tool_use).
  6. Record usage tokens.

9. Tool use workflow

  1. Define tools with JSON input_schema; set tool_choice (auto / any / tool).
  2. If stop_reason is tool_use, read the tool_use block(s) and validate input.
  3. Execute the tool in your own code.
  4. Append the assistant tool_use turn + a user turn with a tool_result (tool_use_id).
  5. Call again; repeat until end_turn. See recipes/tool-use.md.

10. Vision & documents

  • Add image content blocks (base64 or URL) for vision; downscale images to save tokens.
  • Add document content blocks (PDF) for long documents.
  • Both consume input tokens by size — estimate first. See recipes/vision-analysis.md.

11. Extended thinking

Enable thinking: { "type": "enabled", "budget_tokens": N } for genuinely hard reasoning (math proofs, complex planning). It costs extra tokens — do not enable for simple tasks.

12. Prompt caching

Mark large, stable context (system prompt, long docs, tool schemas) with cache_control: { "type": "ephemeral" } to read it from cache at a steep discount on repeated calls. Verify hits via usage.cache_read_input_tokens. Keep the cached prefix byte-identical.

13. Cost control (CRITICAL)

Every anthropic_messages / /messages / /messages/batches call is billed per token.

  • Always set max_tokens to the smallest value that fits.
  • Pick Haiku unless quality requires more.
  • Cache repeated large context.
  • Batch bulk non-interactive work (~50% off) via anthropic_request/messages/batches.
  • Estimate with anthropic_count_tokens before large jobs.
  • Avoid extended thinking and oversized images/docs unless needed. See prompts/cost-control.md.

14. Error handling

Error Reaction
401 authentication_error Fix the key. Do not retry.
429 rate_limit_error Backoff/retry; reduce rate or batch.
529 overloaded_error Backoff/retry (transient).
400 invalid_request_error Fix params (e.g. missing max_tokens, missing version/beta). Don't retry unchanged.
See reference/common-errors.md.

15. Security

  • Never expose or hardcode ANTHROPIC_API_KEY; use env / placeholder your_api_key_here.
  • Never echo the x-api-key header or print the key.
  • Treat model output and tool-use arguments as untrusted; validate before acting; watch for prompt injection.

16. Structured output

Prefer tool forcing for reliable JSON: define a tool whose input_schema is your target schema and set tool_choice: { "type": "tool", "name": "..." }. Read the structured object from the tool_use.input. Lower temperature for determinism.

17. Agent checklist

  • Cheapest viable model selected.
  • max_tokens set.
  • System prompt set; full history passed.
  • Large stable context cached.
  • Tokens estimated for big jobs.
  • usage recorded; stop_reason handled.
  • Errors handled per table; 401 not retried.
  • Key never exposed; outputs treated as untrusted.

18. Example workflows

19. Common mistakes

  • Forgetting max_tokens → 400. Always include it.
  • Dropping the version header → 400. Keep ANTHROPIC_VERSION set.
  • Using Opus for trivial tasks → wasted money. Default to Haiku.
  • Retrying a 401 → never fixes it.
  • Not passing full history → the model "forgets" (API is stateless).
  • Unbounded max_tokens → runaway cost.

20. Maintenance

Verification needed: confirm model IDs, pricing, and feature availability with https://docs.anthropic.com/en/api

安全使用建议
Install only if you intend to use Anthropic’s API. Keep the API key in environment variables, do not paste secrets into prompts, and review or redact sensitive conversations, screenshots, documents, PII, PHI, financial, or internal business data before sending them to a third-party model provider.
能力标签
requires-sensitive-credentials
能力评估
Purpose & Capability
The skill purpose is to teach agents how to use Anthropic Claude API tools for chat, vision, tool use, cost control, and errors; the documented capabilities fit that purpose.
Instruction Scope
Instructions to send full conversation history, images, documents, and tool schemas to Anthropic are expected for this API workflow, but the recipes emphasize cost more than privacy minimization.
Install Mechanism
Artifacts are Markdown documentation and tests only; no executable scripts, package installs, postinstall hooks, or automatic runtime behavior were found.
Credentials
Use of ANTHROPIC_API_KEY and external Anthropic API calls is disclosed and proportionate to the skill, with explicit guidance not to expose or hardcode the key.
Persistence & Privilege
No local persistence, background workers, privilege escalation, broad local indexing, or credential/session harvesting behavior was found; prompt caching is described as an API feature for repeated context.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install anthropic-api-al
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /anthropic-api-al 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Anthropic (Claude) API Skill v1.0.0 - Initial public release providing a comprehensive guide and operational checklist for safe, efficient, and cost-aware use of Anthropic's Claude API via the MCP server. - Details best practices for model selection, vision and document handling, tool-use workflows, prompt caching, and cost control. - Coverage includes environment setup, structured output enforcement, extended thinking configuration, security safeguards, and robust error handling. - Includes clear agent checklists, common pitfalls, and links to example workflows and recipes for typical integrations. - Emphasizes never to expose API keys and to use the cheapest viable model by default (Haiku).
元数据
Slug anthropic-api-al
版本 1.0.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

anthropic api 是什么?

Integrate with Anthropic Claude API to generate chat, tool use, vision, document analysis, and coding responses while controlling cost and handling errors. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 49 次。

如何安装 anthropic api?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install anthropic-api-al」即可一键安装,无需额外配置。

anthropic api 是免费的吗?

是的,anthropic api 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

anthropic api 支持哪些平台?

anthropic api 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 anthropic api?

由 Simon-Pierrre Boucher(@simonpierreboucher02)开发并维护,当前版本 v1.0.0。

💬 留言讨论