Everything you need to use Claude in one page. Bookmark this. Come back whenever you need a quick reference for models, APIs, pricing, or code snippets.
This is Article 26 in the Claude AI — From Zero to Power User series.
Models (March 2026)
| Model | ID | Context | Max Output | Input (per 1M) | Output (per 1M) |
|---|---|---|---|---|---|
| Opus 4.6 | claude-opus-4-6 | 200K | 32K | $5.00 | $25.00 |
| Sonnet 4.6 | claude-sonnet-4-6 | 200K | 16K | $3.00 | $15.00 |
| Haiku 4.5 | claude-haiku-4-5 | 200K | 8K | $1.00 | $5.00 |
1M Context (Beta): Available for Opus 4.6 and Sonnet 4.6 on Tier 4+ accounts. Requires header: anthropic-beta: interleaved-thinking-2025-05-14. Premium pricing applies above 200K tokens.
Quick Setup
Install SDKs
# Python
pip install anthropic
# TypeScript / Node.js
npm install @anthropic-ai/sdk
Set API Key
export ANTHROPIC_API_KEY="sk-ant-..."
Messages API — Basic Call
Python
import anthropic
client = anthropic.Anthropic()
message = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[
{"role": "user", "content": "Explain REST APIs in 3 sentences."}
],
)
print(message.content[0].text)
TypeScript
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic();
const message = await client.messages.create({
model: "claude-sonnet-4-6",
max_tokens: 1024,
messages: [
{ role: "user", content: "Explain REST APIs in 3 sentences." },
],
});
if (message.content[0].type === "text") {
console.log(message.content[0].text);
}
System Prompt
message = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
system="You are a Python expert. Always include type hints.",
messages=[{"role": "user", "content": "Write a fibonacci function"}],
)
Streaming
Python
with client.messages.stream(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[{"role": "user", "content": "Write a haiku about code"}],
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)
TypeScript
const stream = await client.messages.stream({
model: "claude-sonnet-4-6",
max_tokens: 1024,
messages: [{ role: "user", content: "Write a haiku about code" }],
});
for await (const event of stream) {
if (event.type === "content_block_delta" && event.delta.type === "text_delta") {
process.stdout.write(event.delta.text);
}
}
Tool Use (Function Calling)
import json
message = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
tools=[
{
"name": "get_weather",
"description": "Get current weather for a location",
"input_schema": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "City name"},
},
"required": ["location"],
},
}
],
messages=[{"role": "user", "content": "What is the weather in Berlin?"}],
)
# Check if Claude wants to use a tool
for block in message.content:
if block.type == "tool_use":
print(f"Tool: {block.name}, Input: {json.dumps(block.input)}")
Vision (Image Analysis)
import base64
with open("screenshot.png", "rb") as f:
image_data = base64.standard_b64encode(f.read()).decode()
message = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[
{
"role": "user",
"content": [
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/png",
"data": image_data,
},
},
{"type": "text", "text": "Describe this image."},
],
}
],
)
Note: Images must be base64-encoded. To use a URL, download and encode the image first.
Structured Output (JSON Mode)
message = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
system="Return valid JSON only. No markdown, no explanation.",
messages=[
{
"role": "user",
"content": 'Extract: "John Smith, age 30, john@example.com" → {"name": "...", "age": N, "email": "..."}',
}
],
)
Extended Thinking
message = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=16384,
thinking={
"type": "enabled",
"budget_tokens": 10000,
},
messages=[
{"role": "user", "content": "Solve: find the optimal solution for the traveling salesman problem with 8 cities"}
],
)
for block in message.content:
if block.type == "thinking":
print(f"Thinking: {block.thinking[:200]}...")
elif block.type == "text":
print(f"Answer: {block.text}")
Prompt Caching
message = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
system=[
{
"type": "text",
"text": "Your large system prompt here (must be > 1024 tokens)...",
"cache_control": {"type": "ephemeral"},
}
],
messages=[{"role": "user", "content": "Your question"}],
)
# Check cache usage
print(f"Cache write: {message.usage.cache_creation_input_tokens}")
print(f"Cache read: {message.usage.cache_read_input_tokens}")
Pricing: Cache write costs 25% extra. Cache read costs 90% less. TTL: 5 minutes.
Batch API
batch = client.batches.create(
requests=[
{
"custom_id": "task-001",
"params": {
"model": "claude-sonnet-4-6",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello"}],
},
}
],
)
# Poll for completion
batch = client.batches.retrieve(batch.id)
print(f"Status: {batch.processing_status}")
# Get results when done
results = list(client.batches.results(batch.id))
Pricing: 50% off all models. Results within 24 hours.
Web Search
message = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=4096,
tools=[{"type": "web_search_20250305"}],
messages=[{"role": "user", "content": "What is the latest Python version?"}],
)
Computer Use (Beta)
message = client.beta.messages.create(
model="claude-sonnet-4-6",
max_tokens=4096,
betas=["computer-use-2025-11-24"],
tools=[
{
"type": "computer_20241022",
"name": "computer",
"display_width_px": 1920,
"display_height_px": 1080,
"display_number": 1,
}
],
messages=[{"role": "user", "content": "Take a screenshot"}],
)
Claude Code — Top Commands
| Command | Description |
|---|---|
claude | Start interactive mode |
claude "fix the login bug" | One-shot task |
claude -p "explain this code" | Print mode (no interactive) |
/init | Generate CLAUDE.md for your project |
/model | Switch model |
/clear | Clear conversation |
/compact | Compress conversation history |
/cost | Show session cost |
/permissions | Manage tool permissions |
CLAUDE.md Template
# Project Name
## Tech Stack
- Language: Python 3.12 / TypeScript 5.5
- Framework: FastAPI / Next.js 15
- Database: PostgreSQL with Prisma
## Commands
- Dev: `npm run dev`
- Build: `npm run build`
- Test: `npm test`
- Lint: `npm run lint`
## Rules
- Always use type hints / strict TypeScript
- Write tests for new features
- Use conventional commits
MCP Server (Minimal)
Python
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("my-server")
@mcp.tool()
async def greet(name: str) -> str:
"""Greet someone by name."""
return f"Hello, {name}!"
mcp.run()
TypeScript
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
const server = new McpServer({ name: "my-server", version: "1.0.0" });
server.tool("greet", { name: z.string() }, async ({ name }) => ({
content: [{ type: "text", text: `Hello, ${name}!` }],
}));
const transport = new StdioServerTransport();
await server.connect(transport);
Prompt Engineering — Top 10 Tips
- Be specific — “Find SQL injection bugs” not “review this code”
- Use XML tags —
<rules>,<context>,<output_format> - Give examples — Few-shot examples beat long descriptions
- System prompt first — Put instructions in the system prompt
- One task per prompt — Do not combine unrelated tasks
- Say what NOT to do — “Do not invent problems”
- Specify format — “Return JSON” or “Return a bulleted list”
- Use temperature 0 — For deterministic tasks (code, extraction)
- Give permission to say no — “If unsure, say I don’t know”
- Test and iterate — Use eval datasets, not gut feeling
Cost Quick Reference
| Task | Model | Approx. Cost |
|---|---|---|
| Simple question | Haiku 4.5 | $0.003 |
| Simple question | Sonnet 4.6 | $0.008 |
| Code review (500 lines) | Sonnet 4.6 | $0.05 |
| Document analysis (10 pages) | Sonnet 4.6 | $0.09 |
| Complex reasoning | Opus 4.6 | $0.50 |
| Batch code review | Sonnet 4.6 | $0.025 (50% off) |
| Cached system prompt | Sonnet 4.6 | 90% off cached input |
Rate Limits by Tier
| Tier | Deposit | RPM | TPM (Input) | TPM (Output) |
|---|---|---|---|---|
| 1 | $5 | 50 | 40,000 | 8,000 |
| 2 | $40 | 1,000 | 80,000 | 16,000 |
| 3 | $200 | 2,000 | 160,000 | 32,000 |
| 4 | $400 | 4,000 | 400,000 | 80,000 |
Tier 4 is required for 1M context window beta.
Common Errors
| Error | Cause | Fix |
|---|---|---|
401 Unauthorized | Invalid API key | Check ANTHROPIC_API_KEY |
429 Rate Limit | Too many requests | Add retry with backoff |
529 Overloaded | API busy | Retry after 5-10 seconds |
400 Invalid Request | Bad parameters | Check model ID and message format |
413 Request Too Large | Input too long | Reduce context or use 1M beta |
Retry Pattern
import anthropic
from tenacity import retry, stop_after_attempt, wait_exponential
@retry(stop=stop_after_attempt(3), wait=wait_exponential(min=1, max=30))
def call_claude(messages):
return client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=messages,
)
Official Links
| Resource | URL |
|---|---|
| API Docs | docs.anthropic.com |
| Console | console.anthropic.com |
| Pricing | anthropic.com/pricing |
| Cookbook | github.com/anthropics/anthropic-cookbook |
| Python SDK | github.com/anthropics/anthropic-sdk-python |
| TypeScript SDK | github.com/anthropics/anthropic-sdk-typescript |
| Status | status.anthropic.com |
| Discord | discord.gg/anthropic |