interfaces.LLMUsage on LLMResponse.Usage. OpenAI, Anthropic, and Gemini clients populate the fields when the provider returns them.
An agent run can involve multiple LLM calls — the initial generation, then one more per tool round as the model processes tool results and decides next steps. AgentRunResult.LLMUsage is the sum across all rounds, giving you a single number for the full cost of a run.
Usage fields
CachedPromptTokens is populated by OpenAI automatically (server-side caching, no client option needed) and by Anthropic only when llm.WithPromptCaching(true) is set — it’s 0 for Anthropic otherwise, since caching is disabled by default there.
Run
AgentRunResult.LLMUsage is the sum across all LLM calls in that run — including tool rounds. Use it for cost estimates, quotas, and logging:
Stream
The same aggregate appears onLLMUsage in the AgentEventTypeRunFinished event — Result is an *AgentRunResult:
include_usage surfaces totals on RUN_FINISHED. Example: Stream.
Budget enforcement
To automatically stop or pause a run when a token or cost limit is reached, useWithBudget. It works across all runtimes and covers sub-agent usage transparently without any hook code.
Per-request usage
For per-LLM-call breakdowns — to log each round individually, build cost dashboards, or track iteration-level usage — useAfterLLMHook and inspect in.Response.Usage on each iteration:
Example
Simple Agent
SHOW_LLM_USAGE footer
Related
Budget
Token and cost limits with automatic enforcement
Reasoning
ReasoningTokens from extended thinking
Streaming
Usage on RUN_FINISHED events