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.69× face value — or a flat-rate unlimited plan.
Get an API key See unlimited plansAI 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.