Install
openclaw skills install anthropic-api-alIntegrate with Anthropic Claude API to generate chat, tool use, vision, document analysis, and coding responses while controlling cost and handling errors.
openclaw skills install anthropic-api-alUse this skill to call the Anthropic Claude API correctly, safely, and cost-consciously through the Anthropic MCP server's four tools.
anthropic-claude-api — Anthropic (Claude) API operations skill.
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).
Use Claude for:
ANTHROPIC_API_KEY — required; sent as x-api-key. Never expose it.anthropic-version header — required (default 2023-06-01); the MCP server sends it.ANTHROPIC_BETA (beta features), ANTHROPIC_API_BASE_URL, ANTHROPIC_TIMEOUT_MS, ANTHROPIC_MAX_RETRIES, LOG_LEVEL.| 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). |
Pick the cheapest model that meets quality needs:
claude-opus-4-8 — most capable; hard reasoning, complex agents, deep coding.claude-sonnet-4-6 — balanced; most production work.claude-haiku-4-5 — fast & 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.
max_tokens (required; also your output cost cap).system prompt for role/constraints.messages (the API is stateless).stop_reason (end_turn, max_tokens, stop_sequence, tool_use).usage tokens.tools with JSON input_schema; set tool_choice (auto / any / tool).stop_reason is tool_use, read the tool_use block(s) and validate input.tool_use turn + a user turn with a tool_result (tool_use_id).end_turn. See recipes/tool-use.md.image content blocks (base64 or URL) for vision; downscale images to save tokens.document content blocks (PDF) for long documents.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.
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.
Every anthropic_messages / /messages / /messages/batches call is billed per token.
max_tokens to the smallest value that fits.anthropic_request → /messages/batches.anthropic_count_tokens before large jobs.| 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. |
ANTHROPIC_API_KEY; use env / placeholder your_api_key_here.x-api-key header or print the key.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.
max_tokens set.usage recorded; stop_reason handled.max_tokens → 400. Always include it.ANTHROPIC_VERSION set.max_tokens → runaway cost.anthropic_models to validate IDs.Verification needed: confirm model IDs, pricing, and feature availability with https://docs.anthropic.com/en/api