HomeClaude Code › Agent SDK
OverviewInstallCLI referencePricing & limitsAgent SDKSkills & pluginsGitHubWeb, desktop & IDEModelsErrorsOpen source?TutorialFor studentsQA automation中文指南
Last updated: September 22, 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

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.69× 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 Code for studentsHow to use Claude Code for QA automationClaude Code 怎么用:从安装到日常使用