Home › Claude Code › Agent SDK
OverviewInstallCLI referencePricing & limitsAgent SDKSkills & pluginsGitHubWeb, desktop & IDEModelsErrorsOpen source?TutorialFor studentsQA automationvs Cursorvs Codex & OpenCodeSubagentsHooksMCPEcosystemVS CodeOpenRouterRate limits中文指南
Last updated: November 06, 2026

The Claude Code SDK, now the Claude Agent SDK

The same agent loop that runs in your terminal is available as a library. Anthropic renamed the Claude Code SDK to the Claude Agent SDK when it became clear people were building far more than coding tools with it.

TLDR

  • Python: pip install claude-agent-sdk; TypeScript: npm install @anthropic-ai/claude-agent-sdk.
  • You get the full agent — file tools, bash, subagents, MCP — driven from code, with permission callbacks.
  • The SDK reads ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY like the CLI does, so gateway billing applies.

Two ways to automate Claude Code

The lightweight route is the CLI's print mode — claude -p from any language, with JSON output. The full route is the Agent SDK, which exposes the loop, the tool set, hooks and permissions as objects you control.

Python

import anyio
from claude_agent_sdk import query, ClaudeAgentOptions

async def main():
    options = ClaudeAgentOptions(
        allowed_tools=["Read", "Edit", "Bash"],
        max_turns=8,
    )
    async for message in query(
        prompt="add type hints to utils.py and run the tests",
        options=options,
    ):
        print(message)

anyio.run(main)

TypeScript

import { query } from "@anthropic-ai/claude-agent-sdk";

for await (const message of query({
  prompt: "find and fix the flaky test in this repo",
  options: { allowedTools: ["Read", "Edit", "Bash"], maxTurns: 8 },
})) {
  console.log(message);
}

Running it against the gateway

export ANTHROPIC_BASE_URL=https://aiprimetech.io
export ANTHROPIC_API_KEY=your_gateway_key
python agent.py

The SDK spawns the same Claude Code runtime, so the environment variables are all it needs. Long-running agents are where gateway pricing matters most: an autonomous loop can make hundreds of calls an hour, and a flat-rate plan turns that from a cost estimate into a fixed number.

What the SDK adds over print mode

  • Permission callbacks — approve or deny each tool call from your own code.
  • Custom tools via in-process MCP servers, so the agent can call your functions.
  • Hooks on tool events, session lifecycle and errors.
  • Subagents and structured output, without shelling out and parsing text.

Frequently asked questions

Is the Claude Code SDK the same as the Anthropic SDK?

No. The Anthropic SDK calls the Messages API directly. The Claude Agent SDK (formerly Claude Code SDK) runs the whole agent — tools, files, bash, subagents — on top of it.

Which languages does the Agent SDK support?

Python and TypeScript officially; anything else can drive the CLI's print mode with JSON output.

Does the SDK work with a custom base URL?

Yes. It inherits ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY from the environment, exactly like the CLI.

Run Claude Code on the gateway

Same models, two environment variables, credits at 7.69231× face value — or a flat-rate unlimited plan.

Get an API key See unlimited plans

AI Prime Tech is an independent API gateway and is not affiliated with, endorsed by, or sponsored by Anthropic. “Claude” and “Claude Code” are trademarks of Anthropic. Claude Code features described here follow Anthropic’s public documentation at the time of writing and change frequently; prices and model lists on this page are read from this gateway’s live settings.

More Claude Code guides

Claude Code: the complete guideHow to install Claude CodeClaude Code CLI documentation: commands and flagsClaude Code pricing and limits, explainedClaude Code skills and pluginsClaude Code in GitHub: the App, the Action and @claudeDoes Claude Code have a web interface? Web, desktop and IDE explainedWhich model Claude Code uses, and how to change itClaude Code errors and how to fix themIs Claude Code open source?Claude Code tutorial: your first real sessionClaude for students: Claude Code, the API and what education actually gets youHow to use Claude Code for QA automationClaude Code vs Cursor: which one, when — and how to run bothClaude Code vs Codex vs OpenCode: the terminal agents comparedClaude Code subagents: how they work, how to define them, and agent teamsClaude Code hooks: deterministic control over what the agent doesClaude Code MCP: connecting servers, scopes, remote MCP and real examplesThe Claude Code ecosystem: routers, frameworks, plugins and the lists that track themClaude Code in VS Code: the extension, the terminal route, and the errorsHow to use OpenRouter in Claude Code (and when not to)Claude rate limit error: what "API error: rate limit reached" means and how to fix itClaude Code 怎么用:从安装到日常使用