anthropic-sdk
БесплатноБез исполняемых скриптовНе проверенThe Anthropic SDK (Python `anthropic`, TypeScript `@anthropic-ai/sdk`) calls Claude models through the Messages API. Use when a user asks to add Claude to an…
Об этом скилле
Anthropic SDK
Overview
The official SDKs wrap POST /v1/messages. Everything (text, tools, images, thinking) goes through that one endpoint. Current SDK majors: @anthropic-ai/sdk 1.x on npm and anthropic 2.x on PyPI (Python 3.10+; its HTTP layer is httpx2, not httpx). Models retire: claude-sonnet-4-20250514, claude-opus-4-20250514 and claude-opus-4-1-20250805 are retired and return errors, and claude-sonnet-4-5-20250929 retires on 2026-11-30. Check the model status table in the Anthropic docs before hardcoding an id.
Instructions
Current model ids (October 2026)
| Model | Id | Context | $ per 1M in/out |
|---|---|---|---|
| Claude Fable 5.1 (hardest reasoning, long agentic work) | claude-fable-5-1 |
1M | 10 / 50 |
| Claude Opus 5.5 (Anthropic's suggested starting point) | claude-opus-5-5 |
1M | 4 / 20 |
| Claude Sonnet 5.5 (speed and intelligence) | claude-sonnet-5-5 |
1M | 2 / 10 |
| Claude Haiku 5.5 (classification, extraction, routing) | claude-haiku-5-5 |
1M | from 0.10 / 0.50 |
Use these exact strings; do not append dates. Older active ids include claude-opus-4-8 and claude-sonnet-4-6; claude-haiku-4-5-20251001 is active but its retirement is not sooner than 2026-10-15.
Install and create the client
npm install @anthropic-ai/sdk
pip install anthropic
import Anthropic from "@anthropic-ai/sdk";
const anthropic = new Anthropic(); // reads ANTHROPIC_API_KEY from the environment
import anthropic
client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY
Messages
const message = await anthropic.messages.create({
model: "claude-sonnet-5-5",
max_tokens: 4096,
system: "You are a senior backend engineer. Answer with working code and one paragraph of explanation.",
messages: [{ role: "user", content: "Write a sliding-window rate limiter middleware for Express." }],
});
for (const block of message.content) {
if (block.type === "text") console.log(block.text);
}
console.log(message.usage.input_tokens, message.usage.output_tokens, message.stop_reason);
message = client.messages.create(
model="claude-sonnet-5-5",
max_tokens=4096,
system="You are a senior backend engineer.",
messages=[{"role": "user", "content": "Write a sliding-window rate limiter for Flask."}],
)
print(next(b.text for b in message.content if b.type == "text"))
message.content is a list of blocks (text, thinking, tool_use, ...), so check block.type before reading .text. The API is stateless: send the whole history each time, appending the assistant's message.content as the next assistant turn. Assistant prefill (ending messages with an assistant turn) is rejected on current models; steer format with the system prompt or structured outputs (output_config: { format }). Do not send temperature, top_p or top_k: current models reject them with a 400 error.
Streaming
Stream any request with long output or a large max_tokens to avoid HTTP timeouts:
const stream = anthropic.messages.stream({
model: "claude-sonnet-5-5",
max_tokens: 16000,
messages: [{ role: "user", content: "Explain how B-trees stay balanced." }],
});
stream.on("text", (t) => process.stdout.write(t));
const final = await stream.finalMessage(); // complete Message with usage and stop_reason
with client.messages.stream(model="claude-sonnet-5-5", max_tokens=16000,
messages=[{"role": "user", "content": "Explain B-trees."}]) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)
final = stream.get_final_message()
Tool use
Define tools with a JSON Schema; when stop_reason is "tool_use", run every tool_use block and return all results together in one user message:
const tools: Anthropic.Tool[] = [{
name: "get_order_status",
description: "Look up the shipping status of an order by its id. Use when the customer asks where their order is.",
input_schema: { type: "object", properties: { order_id: { type: "string", description: "e.g. ORD-20417" } }, required: ["order_id"] },
}];
const messages: Anthropic.MessageParam[] = [{ role: "user", content: "Where is order ORD-20417?" }];
while (true) {
const res = await anthropic.messages.create({ model: "claude-sonnet-5-5", max_tokens: 4096, tools, messages });
messages.push({ role: "assistant", content: res.content });
if (res.stop_reason !== "tool_use") break;
const results: Anthropic.ToolResultBlockParam[] = [];
for (const block of res.content) {
if (block.type !== "tool_use") continue;
const status = await lookupOrder((block.input as { order_id: string }).order_id); // your function
results.push({ type: "tool_result", tool_use_id: block.id, content: JSON.stringify(status) });
}
messages.push({ role: "user", content: results });
}
Return is_error: true on a tool_result for a failed call rathe
Установить anthropic-sdk в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл anthropic-sdk?
The Anthropic SDK (Python `anthropic`, TypeScript `@anthropic-ai/sdk`) calls Claude models through the Messages API. Use when a user asks to add Claude to an app, build a chatbot, stream Claude responses, give Claude tools (function calling), send images or PDFs, turn on adaptive thinking, count tokens, or pick a current Claude model id. Covers client setup, streaming, tool use, vision, thinking and effort, and current model ids and breaking changes.
Как установить скилл anthropic-sdk?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл anthropic-sdk запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic