# Anthropic SDK The Anthropic SDK is the official client library for [[Anthropic]]'s [[Claude]] family of models. It is a *model SDK*: a thin, well-typed wrapper over Anthropic's HTTP API. Not to be confused with [[Claude Code SDK]] (the agent-runtime SDK that embeds the entire Claude Code execution loop) ; this is the lower layer both Claude Code and any custom Claude integration sit on top of. Officially supported in TypeScript / Node.js (`@anthropic-ai/sdk`) and Python (`anthropic`). Community-maintained ports exist for Go, Java, Ruby. ## Surface Area The SDK covers the full Claude API surface: - **Messages API** ; the modern conversation endpoint with multi-turn, tool use, vision, and thinking - **Streaming** ; SSE-based token streaming with typed event handlers - **Prompt caching** ; cache breakpoints for ephemeral / persistent reuse, with explicit hit/miss accounting - **Batch API** ; up to 50% cheaper inference for non-time-sensitive jobs - **Tool use** ; structured tool definitions with parallel execution - **Vision** ; image inputs alongside text - **Citations** ; native source attribution - **Files API** ; upload and reuse files across requests - **Memory** ; persistent context across requests where supported - **Computer use** ; the desktop-control beta capability - **Thinking / extended thinking** ; reasoning-mode parameters - **Provider-side compaction** ; request-level prompt compression ## TypeScript Example ```ts import Anthropic from "@anthropic-ai/sdk"; const client = new Anthropic(); const response = await client.messages.create({ model: "claude-opus-4-7", max_tokens: 1024, messages: [{ role: "user", content: "Explain prompt caching" }], }); ``` ## Python Example ```python import anthropic client = anthropic.Anthropic() response = client.messages.create( model="claude-opus-4-7", max_tokens=1024, messages=[{"role": "user", "content": "Explain prompt caching"}], ) ``` ## Where It Fits in the Stack - **You want Claude in your app, full control of the loop** → use the Anthropic SDK directly. Lowest level, highest flexibility, you build everything else - **You want Claude with provider-neutral abstraction** → use [[Vercel AI SDK]] with `@ai-sdk/anthropic`, or [[LiteLLM]] in Python - **You want the Claude Code *agent loop* (plan, tool, edit, exec) embedded** → use [[Claude Code SDK]] - **You want a fully managed Anthropic-hosted agent runtime** → use [[Claude Managed Agents]] ## Critical Features Worth Knowing - **Prompt caching is the cost lever**: long system prompts and stable context blocks should sit behind cache breakpoints; the savings are 10× on cached tokens. The SDK exposes cache control on every content block. - **Batch API for >24h-tolerable workloads**: half the price, same quality, ideal for evals, dataset enrichment, embeddings-style jobs. - **Thinking mode** ; `thinking: { type: "enabled", budget_tokens: 32000 }` materializes the reasoning trace; helpful for debugging or when the chain-of-thought itself is the artifact. ## License MIT. Source at https://github.com/anthropics/anthropic-sdk-typescript and https://github.com/anthropics/anthropic-sdk-python. ## References - TypeScript SDK: https://github.com/anthropics/anthropic-sdk-typescript - Python SDK: https://github.com/anthropics/anthropic-sdk-python - API reference: https://docs.anthropic.com/en/api/getting-started ## Related - [[Anthropic]] - [[Claude]] - [[Claude Code]] - [[Claude Code SDK]] - [[Claude Managed Agents]] - [[AI SDKs]] - [[Vercel AI SDK]] - [[OpenAI SDK]]