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)

ModelIDContextMax OutputInput (per 1M)Output (per 1M)
Opus 4.6claude-opus-4-6200K32K$5.00$25.00
Sonnet 4.6claude-sonnet-4-6200K16K$3.00$15.00
Haiku 4.5claude-haiku-4-5200K8K$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.


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

CommandDescription
claudeStart interactive mode
claude "fix the login bug"One-shot task
claude -p "explain this code"Print mode (no interactive)
/initGenerate CLAUDE.md for your project
/modelSwitch model
/clearClear conversation
/compactCompress conversation history
/costShow session cost
/permissionsManage 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

  1. Be specific — “Find SQL injection bugs” not “review this code”
  2. Use XML tags<rules>, <context>, <output_format>
  3. Give examples — Few-shot examples beat long descriptions
  4. System prompt first — Put instructions in the system prompt
  5. One task per prompt — Do not combine unrelated tasks
  6. Say what NOT to do — “Do not invent problems”
  7. Specify format — “Return JSON” or “Return a bulleted list”
  8. Use temperature 0 — For deterministic tasks (code, extraction)
  9. Give permission to say no — “If unsure, say I don’t know”
  10. Test and iterate — Use eval datasets, not gut feeling

Cost Quick Reference

TaskModelApprox. Cost
Simple questionHaiku 4.5$0.003
Simple questionSonnet 4.6$0.008
Code review (500 lines)Sonnet 4.6$0.05
Document analysis (10 pages)Sonnet 4.6$0.09
Complex reasoningOpus 4.6$0.50
Batch code reviewSonnet 4.6$0.025 (50% off)
Cached system promptSonnet 4.690% off cached input

Rate Limits by Tier

TierDepositRPMTPM (Input)TPM (Output)
1$55040,0008,000
2$401,00080,00016,000
3$2002,000160,00032,000
4$4004,000400,00080,000

Tier 4 is required for 1M context window beta.


Common Errors

ErrorCauseFix
401 UnauthorizedInvalid API keyCheck ANTHROPIC_API_KEY
429 Rate LimitToo many requestsAdd retry with backoff
529 OverloadedAPI busyRetry after 5-10 seconds
400 Invalid RequestBad parametersCheck model ID and message format
413 Request Too LargeInput too longReduce 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,
    )

ResourceURL
API Docsdocs.anthropic.com
Consoleconsole.anthropic.com
Pricinganthropic.com/pricing
Cookbookgithub.com/anthropics/anthropic-cookbook
Python SDKgithub.com/anthropics/anthropic-sdk-python
TypeScript SDKgithub.com/anthropics/anthropic-sdk-typescript
Statusstatus.anthropic.com
Discorddiscord.gg/anthropic