/major-ai-skills:anthropic-apifrom major-ai-skills
Integrate Anthropic Messages API with pinned Claude models, required max_tokens, tool_use loops, streaming, and prompt caching agents routinely miswire.
Ships in major-ai-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
The Anthropic SDK talks to the Messages API (messages.create / stream). Requests require model and max_tokens; optional system, alternating user/assistant turns, tools, and cache_control breakpoints. Tool use returns tool_use content blocks; the client must execute allowlisted tools and continue with tool_result. Prompt caching prefixes follow tools → system → messages. Pin current model ids (verify deprecations); never invent keys.
┌─────────────────────────────────────────────────────────────┐
│ Anthropic Messages runtime │
│ │
│ messages.create / messages.stream │
│ ├── system (+ optional cache_control) │
│ ├── tools[] (cache breakpoint on last tool) │
│ └── messages[] (user / assistant / tool_result) │
│ │
│ Response │
│ ├── content blocks: text | tool_use | ... │
│ ├── stop_reason: end_turn | tool_use | max_tokens | ... │
│ └── usage: input/output + cache_creation/read tokens │
└─────────────────────────────────────────────────────────────┘
Use when
Do not use when
@openai-api.@llamaindex (still use this skill for Claude calls).ANTHROPIC_API_KEY from environment only — never commit or hardcode.max_tokens explicitly for production; treat stop_reason=max_tokens as a bug until raised or input trimmed.claude-sonnet-4-6 for balanced prod; claude-haiku-4-5 for high-volume). Check deprecation tables before copying old tutorial ids (claude-sonnet-4-5 EOL paths exist).system; never put secrets in user turns that get logged.tool_use, execute only allowlisted tools with schema-validated input; append tool_result and continue until end_turn.cache_control: {"type": "ephemeral"} on the last tool and/or large system blocks; confirm hits via cache_read_input_tokens (short prompts below model minimum silently skip cache).message.id + usage for cost and debugging; redact PII in logs.import os
from anthropic import Anthropic
client = Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])
TOOLS = [
{
"name": "lookup_order",
"description": "Read-only order status by order_id",
"input_schema": {
"type": "object",
"properties": {"order_id": {"type": "string"}},
"required": ["order_id"],
},
"cache_control": {"type": "ephemeral"},
}
]
ALLOWED = {"lookup_order"}
def lookup_order(order_id: str) -> str:
return f"order {order_id}: shipped"
msg = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
system=[
{
"type": "text",
"text": "Support assistant. Use tools for facts. Never invent refunds.",
"cache_control": {"type": "ephemeral"},
}
],
tools=TOOLS,
messages=[{"role": "user", "content": "Status of ORD-1042?"}],
)
messages = [{"role": "user", "content": "Status of ORD-1042?"}]
while msg.stop_reason == "tool_use":
tool_results = []
for block in msg.content:
if block.type != "tool_use":
continue
if block.name not in ALLOWED:
raise PermissionError(block.name)
result = lookup_order(**block.input)
tool_results.append({
"type": "tool_result",
"tool_use_id": block.id,
"content": result,
})
messages.append({"role": "assistant", "content": msg.content})
messages.append({"role": "user", "content": tool_results})
msg = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
system=[{"type": "text", "text": "Support assistant. Use tools for facts.", "cache_control": {"type": "ephemeral"}}],
tools=TOOLS,
messages=messages,
)
for block in msg.content:
if block.type == "text":
print(block.text)
print(msg.usage) # inspect cache_creation_input_tokens / cache_read_input_tokens
with client.messages.stream(
model="claude-sonnet-4-6",
max_tokens=512,
messages=[{"role": "user", "content": "Outline a dbt testing plan in 5 bullets."}],
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)
Validation loop:
python -c "from anthropic import Anthropic; print(Anthropic().messages.create(model='claude-sonnet-4-6', max_tokens=16, messages=[{'role':'user','content':'ping'}]).id)"
| Signature | Likely cause | Fix path |
|---|---|---|
| 401 / 403 | Bad key or workspace permission | Fix ANTHROPIC_API_KEY; check org access |
stop_reason=max_tokens | Cap too low (or thinking uses budget) | Raise max_tokens; shorten context |
| Tool loop errors / stalled | Missing tool_result or wrong tool_use_id | Continue conversation with matching ids |
| Cache never hits (0 read tokens) | Below minimum cacheable tokens; unstable prefix | Enlarge cached prefix; stabilize tools/system order |
| Cache invalidated every turn | Tool defs or system changing; tool_choice churn | Freeze tool schemas; put breakpoint before varying turns |
| High latency | Huge context; no cache | Trim; enable prompt caching on stable prefix |
| Bedrock/Vertex mismatch | Different model ids / headers | Use platform-specific clients and ids |
| Deprecated model errors | Old tutorial id past EOL | Migrate per Anthropic deprecation table |
@ai-evaluation-dataset).@langchain only when graph/checkpoint complexity justifies it.@openai-api — alternate provider@langchain / @llamaindex — frameworks@qdrant / @chromadb — retrieval backends@ai-evaluation-dataset — golden evals@model-tier-routing — route Haiku vs Sonnet vs OpusMANDATORY: Always pass
max_tokens. Keys from environment only. Pin current non-deprecated model ids. Allowlist and validate tools; completetool_use→tool_resultloops correctly. Use prompt caching on stable tool/system prefixes and confirm cache reads in usage. Redact secrets from logs.
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub alivirgo/major-ai-skills --plugin major-ai-skills412 skills in this plugin
/3d-slicerAutomate 3D Slicer research workflows with MRML, VTK/ITK, DICOM data, and Segment Editor. Use for software workflows, not clinical interpretation./abbreviated-git-statusInspect Git branch, staging, and working-tree changes with short or porcelain status output when a compact repository check is needed./ableton-liveAutomate Ableton Live sessions with Python MIDI Remote Scripts, Max for Live, AbletonOSC, and Link synchronization./act-as-a-personal-tutorExplain a subject step by step, assess prior knowledge, and use short exercises to check understanding before advancing.