Skip to content
BENIBIX Learn

ResultMessage

AI🧩 Claude Agent SDKSDK Messages

Also known as SDK result message, total_cost_usd, Claude Agent SDK ResultMessage

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

Think of it like

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

Example

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

Why it matters

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

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 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.

Common mistake

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

Key takeaways

  1. 1
    End of the loop. Always last.
  2. 2
    Subtype says how. success or error.
  3. 3
    Cost is an estimate. Not the bill.