Events

tool_end

{ type: "tool_end", id, tool, ok, summary, meta, durationMs, refused? }

The call finished, failed or was refused. summary is one line to show; meta is what the tool wants you to know, including what it cost.

ok tells you whichrefused is not an errormeta.credits is per tool
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

Fields

idstring

Matches the tool_start, when there was one.

toolstring

The tool's name.

okboolean

true if it ran and returned. false if it threw, or was refused.

summarystring

One line, meant to be shown — « 3 files », « 2/5 done », or the refusal's reason.

metaobject

What the tool reports: a path, a count, credits, a subagent's figures.

durationMsinteger

How long it took. 0 on a call that never ran.

refusedboolean

Present and true when a permission said no, or a mode refused it.

Three endings, two flags

Endingokrefusedsummary holds
It workedtrueabsentwhat it did
It threwfalseabsentthe error message
It was refusedfalsetruewhy — the mode, or « Refused by the user. »
A refusal is a normal outcome

The result goes back to the model, which adapts. Showing it as an error makes a steered run look broken; showing it as a refusal is what it is.

meta, per tool

Toolmeta carries
read, write, movethe path it acted on
todo_writethe whole list
search, fetch, convert, mediacredits
taskthe subagent's name, model, turns, tool calls, credits, stop reason and report
skillthe skill's name and how many files it has

meta.credits is the tool's own cost

It is already included in the next turn event's totalCredits. Show it per line if you like; do not add it to a running total you built from turns.

A task ends once, with its figures

if (e.type === "tool_end" && e.tool === "task") {
  const { agent, turns, toolCalls, credits, stopReason } = e.meta;
  console.log(`${agent}: ${turns} turns, ${toolCalls} calls, ${credits} credits (${stopReason})`);
}
# A subagent's report is the result of its "task" call; its own events carry parentAgent
def on_event(event):
    if event["type"] == "tool_end" and event["tool"] == "task":
        print("subagent finished:", event["summary"])
A subagent's events arrive here too

They carry parentId — the identifier of the task call that started them — and agent, its name. Their own id is prefixed with the task's, so two runs never collide. Test parentId before treating an event as the main run's.