OverpayingForAIPricing desk
9 min read·Last reviewed for accuracy · 2026-09-11·Prices verified · 2026-09-12

Claude Agent SDK Pricing: Anthropic Agent API Cost Explained

What a Claude agent loop costs on the Messages API and the Claude Agent SDK: Opus 5, Sonnet 5 and Haiku 4.5 traces, prompt caching arithmetic, Message Batches, and where a Claude Code subscription beats API billing.

The article text carries the review date. The rate table below is rebuilt from the live catalogue on every deploy.

Fastest win

There is no separate Claude Agent SDK fee. You pay the Messages API token rate of whichever model the loop calls: Opus 5 $5/$25, Sonnet 5 $2/$10, Haiku 4.5 $1/$5 per 1M tokens. On a 12-step agent trace that is $0.92, $0.37 and $0.18 per run, and prompt caching with cache_control cuts each by roughly two-thirds. Under about 50 Sonnet-class runs a month, Claude Code on the $20 Pro plan is cheaper than the API.

What Anthropic charges for an agent: the direct answer

Anthropic bills agents the same way it bills everything else: per input token and per output token on the Messages API, at $5 in / $25 out per 1M tokens for Claude Opus 5, $2 / $10 for Claude Sonnet 5 and $1 / $5 for Claude Haiku 4.5. Tool definitions, tool results and the assistant's tool calls are all ordinary tokens. The Claude Agent SDK, which wraps the Claude Code harness as a library, adds no licence fee; it makes the same API calls with prompt caching applied to its stable prefix.

On a 12-step agent run with a 4,000-token system prompt and tool set, 1,500-token tool results and 300 output tokens per step (166,800 input tokens, 3,600 output tokens in total), the uncached cost is:

Model$/1M in / out12-step runApprox. cachedBatch (50%)
Claude Opus 5$5 / $25$0.924$0.31$0.462
Claude Sonnet 5$2 / $10$0.370$0.12$0.185
Claude Sonnet 4.6$3 / $15$0.554$0.19$0.277
Claude Haiku 4.5$1 / $5$0.185$0.06$0.092

Sonnet 4.6 costs 50% more than Sonnet 5 for the same tier; do not start a new agent on it. Prices are from our catalogue as of 2026-09-11; live rows are on the models page and the Claude pricing page.

Where the tokens go in a Claude tool loop

A Claude agent turn is client.messages.create with tools=[...]. Claude replies with stop_reason: "tool_use" and one or more tool_use blocks; you execute them, append a user message of tool_result blocks, and call again. The request renders as tools, then system, then messages, and all of it is billed on every call.

For the Sonnet 5 12-step trace: 166,800 input tokens × $2 ÷ 1,000,000 = $0.3336, plus 3,600 output tokens × $10 ÷ 1,000,000 = $0.036, total $0.3696. Input is 90% of the bill, and almost all of it is context sent one step earlier. Doubling every assistant turn to 600 tokens adds only $0.036.

Two Anthropic-specific details change the numbers. Adaptive thinking is on by default on Opus 5 and Sonnet 5 and bills as output, so set output_config.effort to low or medium on worker agents. Server-side tools such as web search bill their fetched content as input on top of any per-use charge listed on the vendor page.

Prompt caching with cache_control: the biggest single lever

Anthropic's prompt caching charges roughly 10% of the list input rate for cache reads and roughly 125% for the initial cache write. These are approximate multipliers rather than catalogue rows, but in an agent loop most of each request is a prefix you already sent, so the saving is large.

Mark the end of the stable prefix with cache_control: {"type": "ephemeral"}: the last tool definition (tools render first) and the system prompt, and optionally the most recent tool result so the conversation itself is cached step to step. The default cache lifetime is five minutes, extendable with ttl: "1h" for agents that wait on slow tools.

import anthropic

client = anthropic.Anthropic()
tools = [{
    "name": "search_orders",
    "description": "Find orders by customer email",
    "input_schema": {"type": "object", "properties": {"email": {"type": "string"}},
                     "required": ["email"], "additionalProperties": False},
    "strict": True,
    "cache_control": {"type": "ephemeral"},  # cache the tools prefix
}]
response = client.messages.create(
    model="claude-sonnet-5",
    max_tokens=2000,
    output_config={"effort": "medium"},
    system=[{"type": "text", "text": SYSTEM_PROMPT,
             "cache_control": {"type": "ephemeral"}}],
    tools=tools,
    messages=history,
)
u = response.usage
# Sonnet 5: uncached in $2, cache write ~$2.50, cache read ~$0.20, out $10 per 1M
cost = (u.input_tokens * 2 + u.cache_creation_input_tokens * 2.5
        + u.cache_read_input_tokens * 0.2 + u.output_tokens * 10) / 1_000_000

On the 12-step Sonnet 5 trace the cached total is roughly $0.12 against $0.37 uncached, and on a 30-step run roughly $0.40 against $1.90. If cache_read_input_tokens is zero on step two, something in your prefix is changing between calls. See the prompt caching cost comparison for the per-provider rules.

Opus 5 vs Sonnet 5 vs Haiku 4.5: which tier for which role

Per run, Opus 5 costs 2.5× Sonnet 5 and 5× Haiku 4.5 at the same step count. The question is whether the dearer model finishes in fewer steps or fails less often, because both change cost per successful task more than the per-token rate does.

The cheapest model that still does this reliably: Haiku 4.5 at $0.185 per 12-step run (about $0.06 cached) for well-specified tool work with strict schemas: enrichment, lookups, classify-and-act loops, subagents that read files and report back. It follows strict: true schemas well; note it lacks the effort parameter and uses budget_tokens for extended thinking.

When to pay for Sonnet 5: as the default for anything a person reviews afterwards. At $0.37 per run uncached it is the price-performance anchor of the range, with 1M context, adaptive thinking and effort control.

When to pay for Opus 5: as the planner in a multi-agent setup, for long-horizon coding where a wrong plan wastes dozens of steps, and where one failure costs more than the $0.55 premium per run. Opus 5 also supports mid-conversation system messages, which steer a running agent without breaking the cached prefix. The lowest cost per finished task in practice is Opus 5 planning, Sonnet 5 or Haiku 4.5 executing, all sharing one cached tool prefix. The cheapest LLM for AI agents guide ranks these against other vendors.

Message Batches: half price when latency does not matter

The Message Batches API processes requests asynchronously within 24 hours at roughly 50% of list; batch rows exist in our catalogue for the Anthropic models at that discount. It cannot drive a live loop, where each step depends on the previous result, but it suits the fan-out half of agent work: scoring 5,000 tickets, or running the same 5-step agent over a backlog overnight.

from anthropic.types.message_create_params import MessageCreateParamsNonStreaming
from anthropic.types.messages.batch_create_params import Request

batch = client.messages.batches.create(requests=[
    Request(custom_id=f"ticket-{t.id}",
            params=MessageCreateParamsNonStreaming(
                model="claude-haiku-4-5", max_tokens=1000,
                system=SYSTEM_PROMPT, tools=tools,
                messages=[{"role": "user", "content": t.text}]))
    for t in tickets
])
# Haiku 4.5 batch: ~$0.50 in / ~$2.50 out per 1M instead of $1 / $5

Batch and caching stack: a 5-step Haiku 4.5 agent over 10,000 items costs $455 at list and about $228 in a batch. See LLM batch API pricing for the other vendors' tiers.

When Claude Code on Pro or Max beats paying API rates

Claude Code is included in Claude Pro ($20/month) and Claude Max (from $100/month); used any other way it bills at API rates. The subscription buys a usage allowance rather than a token meter, so the comparison is: how many agent runs would the same money buy on the API?

PlanMonthly priceSonnet 5 runs at $0.37 (uncached)Sonnet 5 runs at ~$0.12 (cached)
Claude Pro$20~54~165
Claude Maxfrom $100~270~830

If a person is driving Claude Code interactively for coding, the subscription almost always wins: interactive sessions are long, context-heavy and cached, and the allowance absorbs them. Pro suits a developer running a handful of sessions a day; Max suits someone who lives in it. Our is Claude Code worth it review has the usage profiles.

The API wins when the agent runs unattended, in parallel, or inside a product. Allowances are per person and rate-limited, so they cannot back a service running 500 agent jobs an hour, and they do not cover the Claude Agent SDK in production. Under roughly 50 Sonnet-class runs a month for one person, buy Pro; above a few hundred unattended runs, use the API with caching and Haiku 4.5 for routine steps.

How to cap spend on a Claude agent

Four controls, applied together:

  • max_tokens per call: 1,000 to 4,000 for tool-calling turns. This bounds a single turn, not the loop.
  • A hard step cap: break after N tool_use responses. Fifteen is generous for most task types.
  • Stop conditions: end on stop_reason == "end_turn", on two identical consecutive tool calls, or on a finish tool the agent must call to declare completion.
  • A per-run USD budget computed from response.usage after every call, using the arithmetic in the snippet above. Abort past your ceiling and log the total per task to track cost per successful task.

At Sonnet 5 rates a $0.50 per-run budget permits about 14 uncached reference steps or roughly 35 cached. Opus 5 and Sonnet 5 also support an advisory task_budget (beta); treat it as a complement to a hard client-side cap. The AI cost calculator turns a monthly run count into a budget line.

Verdict and where to go next

What it costs: $0.18 to $0.92 per 12-step run across the Claude range before caching, roughly $0.06 to $0.31 after. Who should pay API rates: teams running agents unattended, in parallel, or in a product. Who should not: an individual developer using Claude Code interactively, for whom Pro at $20 or Max from $100 is cheaper than any realistic API bill. Cheapest way to get the result: Sonnet 5 as default, Haiku 4.5 for schema-bound worker steps, Opus 5 only as planner, cache_control on tools and system, batches for fan-out. The OpenAI Agents SDK cost and Gemini agent API cost guides cover the other vendors.

Key Takeaways

  • No separate Claude Agent SDK fee: agents bill at Messages API token rates, $5/$25 (Opus 5), $2/$10 (Sonnet 5) and $1/$5 (Haiku 4.5) per 1M tokens
  • A 12-step agent run costs $0.92 on Opus 5, $0.37 on Sonnet 5 and $0.18 on Haiku 4.5 uncached; cache_control cuts each by roughly two-thirds
  • Cache reads are roughly 10% of list input and cache writes roughly 125%; put cache_control on the last tool and the system prompt
  • Message Batches run at roughly 50% of list price and stack with caching, but only for fan-out work, not live loops
  • Claude Pro ($20) covers about 54 uncached Sonnet 5 runs; above a few hundred unattended runs a month the API wins
  • Use Opus 5 as planner, Sonnet 5 as default executor and Haiku 4.5 for strict-schema worker steps

Editorial context

Who is this for?

Developers building agents on the Claude Messages API or the Claude Agent SDK who need a per-run cost, and engineering leads deciding between Claude Code subscriptions and API billing.

When NOT to use this

Chat users deciding between Claude Free and Pro; teams committed to another vendor's stack who only need a cross-vendor number (use the cheapest LLM for agents guide instead).

Pricing insights

Agent cost on Claude is dominated by re-sent context, and Anthropic's cache reads at roughly 10% of list input make cache_control worth more than any model downgrade: a 30-step Sonnet 5 run drops from $1.90 to about $0.40.

Alternatives to consider

GPT-5.4 at $2.50/$15 or Gemini 3.1 Pro at $2/$12 for a Sonnet-class agent; Gemini 3.8 Flash or GPT-5.4 mini at $0.75 input for Haiku-class worker steps; Claude Pro or Max for interactive Claude Code use.

Final verdict

Run Sonnet 5 with cache_control on tools and system, push schema-bound steps to Haiku 4.5, reserve Opus 5 for planning, and only pay API rates once a workload is unattended or above a few hundred runs a month.

Frequently Asked Questions

Does the Claude Agent SDK cost extra?

No. The Claude Agent SDK runs the Claude Code harness on your own infrastructure and bills through the Messages API at the token rate of the model it calls: $5/$25 per 1M tokens for Opus 5, $2/$10 for Sonnet 5, $1/$5 for Haiku 4.5. Inside Claude Code on a Pro or Max plan, the subscription allowance covers it instead.

How much does a Claude agent run cost?

On a 12-step trace with a 4,000-token system prompt and tools, 1,500-token tool results and 300 output tokens per step, a run costs $0.92 on Opus 5, $0.37 on Sonnet 5 and $0.18 on Haiku 4.5 before caching. With cache_control on tools and system the same runs land at roughly $0.31, $0.12 and $0.06.

How does Anthropic prompt caching pricing work for agents?

Cache reads cost roughly 10% of the list input rate and the initial cache write roughly 125%. In an agent loop nearly every request is a prefix you already sent, so marking the last tool definition and the system prompt with cache_control turns most of the bill into cache reads. Check cache_read_input_tokens on step two to confirm it is working.

Should I use Opus 5 or Sonnet 5 for an agent?

Sonnet 5 as the default executor at $2/$10, Opus 5 at $5/$25 as the planner or for long-horizon coding where a bad plan wastes dozens of steps. Opus 5 costs 2.5 times more per run at the same step count, so it pays for itself only when it finishes in fewer steps, fails less often, or a single failure costs more than about $0.55.

Is Claude Code on the Pro plan cheaper than the API?

For one person using it interactively, usually yes. The $20 Pro plan buys roughly what 54 uncached or 165 cached Sonnet 5 agent runs would cost on the API, and interactive coding sessions are exactly the long cached sessions the allowance absorbs well. Unattended, parallel or product agents must be API billed.

Can I use Message Batches for an agent?

Only for the parts that do not depend on a previous step's result. A live tool loop cannot be batched, but running the same short agent over a backlog of 10,000 items can be, at roughly 50% of list price. Batch and caching discounts stack.

Related

Free courses · no sign-up

Still deciding? Learn the basics first, then come back to the prices.

If our calculators helped you cut down on hidden AI wallet leaks, thanks for using them. A tiny fraction of your savings is what keeps our pricing indexes updated daily.

Not sure which AI is cheapest for your use case? Find out in 30 seconds — no signup required.

AI cost intelligence

Stop overpaying for AI tools

Join the OverpayingForAI list for pricing updates, cheaper alternatives, and practical buying guidance.

Now tracking 50+ AI tools, models, platforms, subscriptions, coding tools, and automation products.

We use your email only for OverpayingForAI updates. Unsubscribe anytime.