"gpt-4o-mini". You don’t turn it on, you just read it back.
Quick Start
1
Run an agent and read the total
A bare The numbers are real spend — no
Agent(llm="gpt-4o-mini") records its usage automatically. Read it back with the global collector:metrics=True, no verbose, no display flag required.2
Break usage down per agent
Pass a
name to each agent and the collector rolls usage up under by_agent:How It Works
Accounting happens inside the nativeOpenAIClient after every successful completion — one record per tool-loop iteration — and lands in the global TokenCollector.
Token accounting is on by default and does not depend on
output="verbose", metrics=True, or any display flag. A quiet default agent still records real spend — display flags gate rendering only, never accounting.Session Summary Shape
get_session_summary() returns a plain dict you can read or serialise:
Each metrics block carries
input_tokens, output_tokens, cached_tokens, reasoning_tokens, audio_input_tokens, and audio_output_tokens.
Common Patterns
How much did this run cost?
How much did this run cost?
Reset before, read the summary after — you get the spend for just this run:
Multi-agent breakdown
Multi-agent breakdown
by_agent gives a per-agent rollup so you can attribute spend to the right worker:Every tool-loop iteration is billed and recorded
Every tool-loop iteration is billed and recorded
When an agent calls a tool and then completes, each model call is its own paid iteration. A single tool-using turn therefore records
total_interactions == 2 — one for the tool-call step and one for the final answer — and both are summed into the totals.Latest Call Only
For CLI or Harbor envelopes that need the most recent completion’s usage — not the session total — readOpenAIClient.last_token_metrics. It exposes the latest completion’s TokenMetrics and is cleared when a response carries no usable usage.
Related
Gateway
Unified control plane for agents, tools, and delivery.
Observability
Trace and monitor agent runs end to end.
Output Config
Control what an agent renders vs what it records.

