# Claude Agent SDK Cost Tracking

> Reading what an agent run cost, from the messages it sends back.

**Field:** Artificial Intelligence  
**Category:** Claude Agent SDK  
**Also known as:** Agent SDK Cost Tracking, Agent SDK cost, modelUsage

## Think of it like

It is like a shop till that adds up your basket. The bank still has the real bill.

## Definition

Agent SDK cost tracking is reading what a run spent from the messages it sends back. The result message carries total_cost_usd for the whole call, and modelUsage splits it by model. Each assistant message also has its own token counts. When Claude calls tools side by side, those messages share one ID, so count each ID once. All these costs are estimates made on your machine, not the bill.

## Example

A team logs total_cost_usd for each run. They see one kind of task costs ten times more, and give it a smaller model.

## Why it matters

Agents can spend a lot without anyone noticing. Tracking it per run shows where the money goes.

## Common mistake

Billing customers from total_cost_usd. It is an estimate, so use your real bill for that.

## Three principles

- **Total on the result.** total_cost_usd.
- **Count each ID once.** Parallel calls share one.
- **An estimate.** Not the bill.

## Related terms

- [ResultMessage](https://learn.benibix.com/term/ai/sdk-result-message)
- [maxBudgetUsd Option](https://learn.benibix.com/term/ai/max-budget-usd-option)
- [Token Usage](https://learn.benibix.com/term/development/token-usage)
- [Prompt Caching](https://learn.benibix.com/term/ai/prompt-caching)
- [Claude Agent SDK Hosting](https://learn.benibix.com/term/ai/agent-sdk-hosting)

![A stream of messages from one run. Step one sends three assistant messages with the same ID, marked count once. Step two sends one with a new ID. At the end, the result message shows total_cost_usd, marked an estimate.](https://learn.benibix.com/diagrams/ai9-sdk-cost.svg)

---

Source: https://learn.benibix.com/term/ai/agent-sdk-cost-tracking
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-20
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
