Learn Claude API

Build with Anthropic's Claude models through the Messages API and Python SDK

24 lessons · 4 hours · 4 levels · covers Claude API as of Oct 2026 (anthropic Python SDK 1.x, Claude 5.5 models)

The Claude API is Anthropic's developer platform for building applications on Claude models. You call the Messages API, usually through the official Python SDK `anthropic`, to generate text, read images and PDFs, use tools, return structured JSON and run agents, with production features such as streaming, prompt caching, batches and the Claude Agent SDK.

Before you start

Claude API builds on these; the tree links to the exact lessons you need.

How deep do you want to go?

1. EssentialsRead and write simple code, do the everyday basics8 lessons · 1 hour in total
2. PracticalUse it productively at work, with the usual idioms15 lessons · 2 hours in total
3. AdvancedThe less common features, performance and trade-offs20 lessons · 3 hours in total
4. ExpertInternals and the edge cases experts know24 lessons · 4 hours in total

The Claude API tree

Claude APIThe Claude Developer PlatformThe ClaudeDeveloper PlatformAPI key and Python SDK setupAPI key and PythonSDK setupYour first Messages API callYour first MessagesAPI callStop reasons and token usageStop reasons andtoken usageSystem prompts in the Messages APISystem prompts inthe Messages APIMulti-turn conversationsMulti-turnconversationsStreaming responsesStreaming responsesChoosing a Claude modelChoosing a ClaudemodelImages and PDFsImages and PDFsThe Files APIThe Files APITool use: the request-run-return loopTool use: therequest-run-return…Structured outputs (JSON)Structured outputs(JSON)Errors, retries and timeoutsErrors, retries andtimeoutsCounting tokens before sendingCounting tokensbefore sendingServer tools: web search and code executionServer tools: websearch and code ex…Calling a model through an APICalling a modelthrough an APIVirtual environments and pipVirtual environmentsand pipPrompts, messages and rolesPrompts, messagesand rolesTokensTokensSystem prompts and instructionsSystem prompts andinstructionsThe context windowThe context windowTool calling (function calling)Tool calling (functioncalling)Structured output (JSON)Structured output(JSON)Classes and instancesClasses andinstancesExceptions in depthExceptions in depth
Essentials and Practical shown (15 of 24 lessons); the full list is below. Click a lesson to read it.

All 24 lessons, in order

Getting started

  1. The Claude Developer Platform · Essentials · 7 min

    What the Claude Developer Platform is, what the Messages API does, and which Anthropic tools sit around it.

  2. API key and Python SDK setup · Essentials · 8 min

    Create an API key in the Console, store it in an environment variable and install the anthropic package.

  3. Choosing a Claude model · Essentials · 8 min

    Compare the current model tiers by capability, speed and cost, and list models from code.

The Messages API

  1. Your first Messages API call · Essentials · 10 min

    Send a request with model, max_tokens and messages, and read the text blocks Claude sends back.

  2. Stop reasons and token usage · Essentials · 8 min

    Read stop_reason to know why Claude stopped, and usage to see how many tokens the call cost.

  3. System prompts in the Messages API · Essentials · 7 min

    Use the top-level system parameter to give Claude its role, rules and context for the whole conversation.

  4. Multi-turn conversations · Essentials · 9 min

    The API remembers nothing between calls; you keep the history and send it back each time.

  5. Streaming responses · Essentials · 8 min

    Show Claude's answer as it is written with messages.stream, and use streaming for long outputs.

Images, PDFs and files

  1. Images and PDFs · Practical · 12 min

    Send images and PDF documents as content blocks so Claude can read photos, charts and documents.

  2. The Files API · Practical · 9 min

    Upload a file once, get a file_id, and reference it in many requests instead of resending the bytes.

Tools, JSON and thinking

  1. Tool use: the request-run-return loop · Practical · 15 min

    Define tools with a JSON Schema, run the tool_use blocks Claude returns, and send back tool_result blocks.

  2. Structured outputs (JSON) · Practical · 12 min

    Make Claude's reply follow a JSON Schema with output_config.format, or parse straight into a Pydantic model.

  3. Server tools: web search and code execution · Practical · 11 min

    Turn on Anthropic-run tools such as web search, web fetch and code execution with one entry in tools.

  4. Extended and adaptive thinking · Advanced · 13 min

    Let Claude reason before answering, steer how hard it thinks with effort, and handle thinking blocks correctly.

Production and cost

  1. Errors, retries and timeouts · Practical · 11 min

    Catch the SDK's typed exceptions, rely on its automatic retries, and set timeouts that fit your app.

  2. Counting tokens before sending · Practical · 7 min

    Use messages.count_tokens to measure a request's input size before you send it.

  3. Prompt caching · Advanced · 13 min

    Mark the stable start of your prompt with cache_control so repeated requests reuse it cheaply and faster.

  4. Message Batches for bulk jobs · Advanced · 12 min

    Submit thousands of requests at once, collect results within 24 hours, and pay about half price.

  5. Rate limits and spend limits · Advanced · 10 min

    Understand requests and tokens per minute, usage tiers, rate-limit headers and why some 429s should not be retried.

  6. Controlling cost and latency · Expert · 12 min

    Combine model choice, effort, max_tokens, caching, batches and monitoring into a cost strategy.

Agents

  1. Tool runner and MCP connector · Advanced · 13 min

    Let the SDK's beta tool runner drive the tool loop, and connect remote MCP servers directly from the Messages API.

  2. Claude Agent SDK vs the raw API · Expert · 15 min

    Use the Claude Agent SDK to embed Claude Code's agent loop and tools in your app, and know when the raw API is better.

Quality and safety

  1. Evaluating Claude apps · Expert · 14 min

    Define success criteria, build a test set and grade outputs with code or with a second model before you ship changes.

  2. Safety, prompt injection and guardrails · Expert · 14 min

    Screen inputs with a small model, keep untrusted content in tool results, limit tool power and handle refusals.