# ResultMessage

> The last message of a run. It has the final text, the cost and how it ended.

**Field:** Artificial Intelligence  
**Category:** Claude Agent SDK  
**Also known as:** SDK result message, total_cost_usd, Claude Agent SDK ResultMessage

## Think of it like

It is like the slip you get at the end of a shop visit.

## Definition

ResultMessage is the message that marks the end of the agent loop. It holds the final text, the tokens used, a guess at the cost, the number of turns and the session ID. Its subtype says how the run ended: success, or an error such as hitting max turns. The result text is there only on success, so check the subtype first.

## Example

Leo's job runs every night. It saves the session ID and cost from each ResultMessage, so he can resume and budget.

## Example code

```typescript
if (m.type === "result" && m.subtype === "success") {
  console.log(m.result, m.total_cost_usd);
}
```

Read the answer and the cost, only on success.

## Why it matters

It is the one message that says whether the task worked and what it cost.

## Common mistake

Treating total_cost_usd as the bill. It is an estimate made on your machine, not billing data.

## Three principles

- **End of the loop.** Always last.
- **Subtype says how.** success or error.
- **Cost is an estimate.** Not the bill.

## Related terms

- [Result Subtype](https://learn.benibix.com/term/ai/result-subtype)
- [maxBudgetUsd Option](https://learn.benibix.com/term/ai/max-budget-usd-option)
- [SystemMessage](https://learn.benibix.com/term/ai/sdk-system-message)
- [Claude Agent SDK Cost Tracking](https://learn.benibix.com/term/ai/agent-sdk-cost-tracking)

---

Source: https://learn.benibix.com/term/ai/sdk-result-message
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.
