using-anthropic-platform
Claude SDK development with Messages API, Tool Use, Extended Thinking, streaming, and prompt caching
What this skill does
# Anthropic Claude SDK - Quick Reference
## When to Use
Load this skill when:
- `anthropic` package in `requirements.txt` or `pyproject.toml`
- `@anthropic-ai/sdk` in `package.json` dependencies
- `ANTHROPIC_API_KEY` environment variable present
- User mentions "Anthropic", "Claude", or Claude models
**For detailed patterns**: See [REFERENCE.md](./REFERENCE.md)
---
## Table of Contents
1. [Claude Models](#claude-models-january-2026)
2. [Quick Start](#quick-start)
3. [Messages API Essentials](#messages-api-essentials)
4. [Streaming](#streaming)
5. [Tool Use (Function Calling)](#tool-use-function-calling)
6. [Extended Thinking](#extended-thinking)
7. [Vision](#vision)
8. [Prompt Caching](#prompt-caching)
9. [Error Handling](#error-handling)
10. [Platform Features](#platform-features)
11. [Further Reading](#further-reading)
---
## Claude Models (January 2026)
| Model | Context | Max Output | Thinking | Best For |
|-------|---------|------------|----------|----------|
| `claude-opus-4-5-20251101` | 200K | 32K | Yes | Maximum intelligence |
| `claude-sonnet-4-20250514` | 200K | 64K | Yes | Complex reasoning, coding |
| `claude-3-5-sonnet-20241022` | 200K | 8K | No | Standard tasks |
| `claude-3-5-haiku-20241022` | 200K | 8K | No | Simple chat, Q&A (cheapest) |
### Model Selection
```
Simple chat/Q&A -> claude-3-5-haiku (cheapest)
Standard tasks -> claude-3-5-sonnet
Complex reasoning/coding -> claude-sonnet-4 or claude-opus-4-5
Extended thinking needed -> claude-sonnet-4 or claude-opus-4-5
Batch processing -> Any model (50% cost savings)
```
### Pricing (per 1M tokens)
| Model | Input | Output | Cache Read |
|-------|-------|--------|------------|
| claude-opus-4-5 | $15.00 | $75.00 | $1.50 |
| claude-sonnet-4 | $3.00 | $15.00 | $0.30 |
| claude-3-5-sonnet | $3.00 | $15.00 | $0.30 |
| claude-3-5-haiku | $0.80 | $4.00 | $0.08 |
---
## Quick Start
### Python
```python
from anthropic import Anthropic
client = Anthropic() # Uses ANTHROPIC_API_KEY env var
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello, Claude!"}]
)
print(message.content[0].text)
```
### TypeScript
```typescript
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic();
const message = await client.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello, Claude!' }]
});
console.log(message.content[0].text);
```
### Async Python
```python
import asyncio
from anthropic import AsyncAnthropic
async def main():
client = AsyncAnthropic()
message = await client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello!"}]
)
print(message.content[0].text)
asyncio.run(main())
```
---
## Messages API Essentials
### With System Prompt
```python
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
system="You are a helpful coding assistant. Be concise.",
messages=[{"role": "user", "content": "Explain async/await."}]
)
```
### Multi-Turn Conversation
```python
messages = [
{"role": "user", "content": "What is Python?"},
{"role": "assistant", "content": "Python is a programming language..."},
{"role": "user", "content": "How do I install it?"}
]
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=messages
)
```
### Common Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `model` | string | Model ID (required) |
| `max_tokens` | int | Max response tokens (required) |
| `messages` | array | Conversation messages (required) |
| `system` | string | System prompt |
| `temperature` | float (0-1) | Randomness |
| `tools` | array | Tool definitions |
| `stream` | boolean | Enable streaming |
---
## Streaming
### Basic Streaming
```python
with client.messages.stream(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{"role": "user", "content": "Write a story."}]
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)
```
### Async Streaming
```python
async with client.messages.stream(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}]
) as stream:
async for text in stream.text_stream:
print(text, end="", flush=True)
```
---
## Tool Use (Function Calling)
### Define Tools
```python
tools = [{
"name": "get_weather",
"description": "Get weather for a location",
"input_schema": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "City, e.g., San Francisco"}
},
"required": ["location"]
}
}]
```
### Tool Use Loop
```python
def process_with_tools(user_message: str) -> str:
messages = [{"role": "user", "content": user_message}]
while True:
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
tools=tools,
messages=messages
)
if response.stop_reason == "end_turn":
return response.content[0].text
# Process tool calls
tool_results = []
for block in response.content:
if block.type == "tool_use":
result = execute_tool(block.name, block.input)
tool_results.append({
"type": "tool_result",
"tool_use_id": block.id,
"content": json.dumps(result)
})
messages.append({"role": "assistant", "content": response.content})
messages.append({"role": "user", "content": tool_results})
```
---
## Extended Thinking
For complex reasoning tasks (Claude 4 models only):
```python
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=16000,
thinking={
"type": "enabled",
"budget_tokens": 10000 # Tokens allocated for thinking
},
messages=[{"role": "user", "content": "Solve this complex problem..."}]
)
for block in response.content:
if block.type == "thinking":
print("Thinking:", block.thinking)
elif block.type == "text":
print("Response:", block.text)
```
### Budget Guidelines
| Task Complexity | Budget |
|-----------------|--------|
| Simple reasoning | 2,000 - 5,000 |
| Moderate | 5,000 - 10,000 |
| Complex | 10,000 - 20,000 |
---
## Vision
### Image from Base64
```python
import base64
with open("image.jpg", "rb") as f:
image_data = base64.standard_b64encode(f.read()).decode()
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{
"role": "user",
"content": [
{"type": "image", "source": {
"type": "base64",
"media_type": "image/jpeg",
"data": image_data
}},
{"type": "text", "text": "Describe this image."}
]
}]
)
```
### Supported Types
- Images: `image/jpeg`, `image/png`, `image/gif`, `image/webp`
- Documents: `application/pdf`
---
## Prompt Caching
90% cost savings for repeated content (>1024 tokens):
```python
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
system=[{
"type": "text",
"text": long_system_prompt,
"cache_control": {"type": "ephemeral"}
}],
messages=[{"role": "user", "content": "Question"}]
)
# Check cache usage
print(f"Cache read: {message.usage.cache_read_input_tokens}")
```
---
## Error Handling
```python
from anthropic import (
Anthropic, RateLimitError, AuthenticationError, APIConnectionError
)
import time
def safe_message(messages, max_retries=3):
for attempt in range(max_retries):
Related in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.