Skip to content
BENIBIX Learn

Claude Agent SDK Cost Tracking

AI🧩 Claude Agent SDKAgent SDK Deployment

Also known as Agent SDK Cost Tracking, Agent SDK cost, modelUsage

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

Think of it like

It is like a shop till that adds up your basket. The bank still has the real 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.

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.
Count each message ID once, then read the total from the result.

Common mistake

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

Key takeaways

  1. 1
    Total on the result. total_cost_usd.
  2. 2
    Count each ID once. Parallel calls share one.
  3. 3
    An estimate. Not the bill.