Claude API cheatsheet

Claude API: Setup and first request

7 common Claude API tasks.

Install the Python SDK

Install the official Anthropic SDK for Python.

pip install anthropic

Install the TypeScript SDK

Install the official SDK for TypeScript and JavaScript.

npm install @anthropic-ai/sdk

Set your API key

The SDKs read ANTHROPIC_API_KEY from the environment. Use your own key and keep it out of source control.

export ANTHROPIC_API_KEY="your-api-key"

Send your first message (Python)

Create a client and send one message. The response content is a list of blocks, so check each block's type.

import anthropic

client = anthropic.Anthropic()

response = client.messages.create(
    model="claude-opus-5-5",
    max_tokens=16000,
    messages=[{"role": "user", "content": "What is the capital of France?"}],
)
for block in response.content:
    if block.type == "text":
        print(block.text)

Send your first message (TypeScript)

The same request with the TypeScript SDK.

import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic();

const response = await client.messages.create({
  model: "claude-opus-5-5",
  max_tokens: 16000,
  messages: [{ role: "user", content: "What is the capital of France?" }],
});
for (const block of response.content) {
  if (block.type === "text") console.log(block.text);
}

Send your first message (curl)

The raw HTTP request behind the SDKs. Parse responses with jq rather than grep.

curl https://api.anthropic.com/v1/messages \
  -H "Content-Type: application/json" \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2026-10-21" \
  -d '{
    "model": "claude-opus-5-5",
    "max_tokens": 16000,
    "messages": [{"role": "user", "content": "What is the capital of France?"}]
  }'

Pick a model

Model IDs for the current generation. Check the models overview for the latest list, context windows and prices.

claude-opus-5-5     # most capable general model
claude-sonnet-5-5   # fast, strong at coding and agents
claude-haiku-5-5    # fastest and cheapest
claude-fable-5-1    # most capable, for the hardest tasks

Was this page helpful?