Guide
Claude Agent SDK: what it is, Python and TypeScript, pricing, and the subscription rules
Claude Code as a library. How to install and call it, what it costs, why products need an API key rather than a Claude login, and when Managed Agents fits better.
The Claude Agent SDK is Claude Code packaged as a library: in Anthropic's words it "gives you the same tools, agent loop, and context management that power Claude Code, programmable in Python and TypeScript." Install it with pip install claude-agent-sdk or npm install @anthropic-ai/claude-agent-sdk, set an Anthropic API key, and call query() with a prompt; Claude can then read and edit files, run commands and use MCP tools under the permissions you set. It was called the Claude Code SDK until September 2025. There's no separate fee: you pay Anthropic's API rates for the tokens. Products built on it must use API keys, because Anthropic doesn't allow third-party apps to offer Claude.ai login or route requests through Pro or Max plans.
Key takeaways
- What: the agent loop behind Claude Code, with its built-in tools (Read, Write, Edit, Bash, Grep, web search and more), permissions, hooks, sessions and MCP.
- Languages: Python (MIT licensed) and TypeScript; for other languages, run the CLI with
claude -p --output-format json(Claude Code headless mode). - Cost: API token rates; a container to host it costs far less than the tokens.
- Auth: an API key, or Bedrock, Google Cloud or Microsoft Foundry. Claude subscriptions are for personal use, not products.
- New credit: Max and Team subscribers get monthly API credits from October 2026 that cover the Agent SDK when it runs on an API key from their linked Console organization.
| Messages API | Agent SDK | Managed Agents | |
|---|---|---|---|
| Agent loop | You write it | Built in | Built in, run by Anthropic |
| Built-in tools | No | Read, Edit, Bash, search and more | Yes |
| Runs where | Your code | A process you operate | Anthropic's cloud or your sandbox |
| Languages | Many client SDKs | Python, TypeScript | Any, over HTTP |
| Price | Tokens | Tokens | Tokens plus $0.08 per session-hour |
| Status | Generally available | Generally available | Beta |
What is the Claude Agent SDK?
A library that runs the Claude Code program inside your own application (Anthropic). Anthropic renamed it from the Claude Code SDK on September 29, 2025, and the packages moved from @anthropic-ai/claude-code and claude-code-sdk to their current names (Anthropic). Two defaults changed: the SDK "no longer uses Claude Code's system prompt by default" (opt in with the claude_code preset), and settings loading is something you control with settingSources.
Claude Code itself isn't open source: its repository's license reads "All rights reserved." The Python SDK wrapper is MIT licensed.
How do you install and use the Agent SDK?
From Anthropic's quickstart (Anthropic):
- Python:
pip install claude-agent-sdk(Python 3.10 or later). - TypeScript:
npm install @anthropic-ai/claude-agent-sdk(Node 18 or later).
Both bundle the Claude Code binary. Set ANTHROPIC_API_KEY, then:
import anyio
from claude_agent_sdk import query
async def main():
async for message in query(prompt="What is 2 + 2?"):
print(message)
anyio.run(main)
query() streams messages back as Claude works. In Python, ClaudeSDKClient keeps one session open across turns and supports interrupts, for chat-style apps.
What can you configure?
- Tools and permissions: allow or deny tools, pick a permission mode, or decide each call in a
canUseToolcallback (Anthropic). Note that a tool allowlist "does not constrain bypassPermissions." - Hooks: run your code before or after tool calls, like Claude Code's hooks (Claude Code hooks).
- MCP: connect MCP servers, or define tools in your own code as an in-process server.
- Subagents, skills and plugins: define subagents in code; skills load from
SKILL.mdfiles (Claude Code skills). - Sessions: resume or fork a conversation, and store sessions so another machine can pick them up.
- Structured output: pass a JSON schema and get validated JSON back.
- Settings isolation: pass
settingSources: []so a repository's own settings and hooks aren't loaded.
How much does the Claude Agent SDK cost?
The SDK is free; usage is billed at API rates per million tokens: Opus 5.5 $4 input and $20 output, Sonnet 5.5 $2 and $10, Haiku 5.5 $0.10 and $0.50 (Claude Code pricing). Anthropic's hosting guide says "token cost typically dominates container infrastructure cost by an order of magnitude or more."
Each result reports total_cost_usd, but Anthropic calls these "client-side estimates, not authoritative billing data," and says not to bill customers from them (Anthropic). max_budget_usd caps a single call.
Monthly API credits: from October 2026, Max 5x subscribers get $100 a month, Max 20x $200 and Team up to $500, usable on the Claude API including "the Claude Agent SDK," but not on interactive Claude Code or cloud providers (Anthropic). They apply only when the SDK or claude -p runs on an API key from your linked Console organization; signed in with your plan, the same usage still counts against your plan's limits.
Can you use a Claude subscription with the Agent SDK?
For your own local use, the SDK runs the same program as Claude Code, and Anthropic's legal page says Pro and Max limits "assume ordinary, individual usage of Claude Code and the Agent SDK." For a product, no. Anthropic's overview says: "Unless previously approved, Anthropic does not allow third party developers to offer claude.ai login or rate limits for their products, including agents built on the Claude Agent SDK," and its legal page tells developers using the SDK to "use API key authentication" (Anthropic).
How do you host the Agent SDK?
Each session is a long-running Claude Code process with its own shell and working folder, not a stateless API call (Anthropic). Anthropic suggests about 1 GiB of memory, 5 GiB of disk and one CPU per agent, a container per task or per user, an egress proxy that allows only listed domains, and credentials kept outside the container. For several customers on one host, isolate settings, memory, config folders and working directories per customer.
Agent SDK vs Managed Agents vs the Messages API
- Messages API: you write the tool loop yourself.
- Agent SDK: the loop, tools, permissions and sessions come built in, running in a process you operate.
- Claude Managed Agents: Anthropic runs the agent loop and sandbox for you; in beta, priced at tokens plus $0.08 per session-hour, and not eligible for zero data retention (Anthropic).
- LangGraph and OpenAI's Agents SDK are model-agnostic frameworks where you bring the tools; Anthropic publishes a recipe for moving from OpenAI's Agents SDK.
What changed in 2026?
From the SDK releases: skills on subagents (January), faster first queries with pre-warming (March), session stores with S3, Redis and Postgres adapters (April), a breaking cleanup in May that replaced the to-do tool with task tools, and, since September 30 in TypeScript, an omitted permission mode can start in auto mode, so pass one explicitly if you need manual approvals (GitHub).
One agent for a whole team
An Agent SDK app runs one agent for whoever calls it. Poly (usepoly.co) runs Claude Code and Codex in a shared browser room: a team works with one agent, everyone sees each step live, and any member can approve a change before it happens. Free to start. What is Poly?
Common questions
What is the Claude Agent SDK?
A Python and TypeScript library that gives you Claude Code's agent loop, built-in tools, permissions, hooks and sessions to use in your own application. It was called the Claude Code SDK until September 2025.
How much does the Claude Agent SDK cost?
The SDK is free; you pay Anthropic's API rates for tokens, such as $2 per million input tokens and $10 output for Sonnet 5.5. Max and Team subscribers get monthly API credits from October 2026 that cover it when it runs on an API key from their linked Console organization.
Can I use my Claude Max subscription with the Agent SDK?
For personal local use it runs on the same login as Claude Code. Products can't: Anthropic doesn't allow third-party developers to offer claude.ai login or plan limits, and asks developers using the SDK to use API keys.
Is the Claude Agent SDK open source?
The Python SDK is MIT licensed. The TypeScript package is under Anthropic's commercial terms, and Claude Code itself, which both run, is not open source.
What is the difference between the Agent SDK and Managed Agents?
With the Agent SDK you run the agent in your own process or container. Managed Agents, in beta, runs the agent loop and sandbox on Anthropic's side for tokens plus $0.08 per session-hour.