Fields
modelstringWhich model served this turn. Not always the one you asked for — a fallback changes it per turn.
durationMsintegerHow long the turn took.
inputTokensinteger|nullWhat the provider counted on the way in.
cachedTokensintegerHow much of that the provider served from its cache.
contextTokensintegerThe size of the conversation as measured. The same number as inputTokens when it is available.
contextLimitintegerThe limit in force — your contextTokens, or the default.
contextPartsobject{ system, tools, memory, messages }, scaled so they add up to the total.
contextClearedintegerHow many tool results have been emptied so far in this run.
creditsintegerWhat this turn cost.
totalCreditsintegerWhat the run has cost so far — turns and paid tools together.
A context gauge
onEvent: (e) => {
if (e.type !== "turn") return;
const pct = Math.round((e.contextTokens / e.contextLimit) * 100);
console.log(`${pct}% of the window · ${e.cachedTokens} cached · ${e.contextCleared} results cleared`);
console.log(e.contextParts); // { system: 2100, tools: 3900, memory: 180, messages: 25024 }
};# Python has no "turn" event: read agent.context and agent.usage whenever a tool finishes
def on_event(event):
if event["type"] != "tool_end":
return
context = agent.context
pct = round(context["tokens"] / context["limit"] * 100)
print(f"{pct}% of the window · {context['cleared']} results cleared")
print(context["parts"]) # {"system": 2100, "tools": 3900, "memory": 0, "messages": 25024}The provider gives the total. The parts are estimated from their size and then scaled so the four add up to it exactly — the proportions are sound, an individual part is close rather than exact.
totalCredits already counts the tools
A paid tool's cost is added to the run total when the tool finishes, so the next turn event already includes it. Adding both counts it twice. And a balance read by the account tool is a balance, not a cost — treating it as one makes a run look enormously expensive.
Which model is in there
The field is the model that served the turn. Watching it is how a silent degradation becomes visible: a run that starts on one model and finishes on a fallback has had a bad time, even if every answer was fine.
cachedTokens is worth showing
A long conversation whose prefix is stable is served largely from cache, and cached input is billed at a fraction of the normal rate. A number that drops to zero between two turns means something near the start of the prompt changed — a new tool, a new storage, a cleared batch.
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.