← All notes

Tracking agent token usage and cached-token savings

Answer: The Agents SDK automatically tracks token usage for every run, so you can monitor costs or enforce limits. In Gemini CLI, the /stats command shows token usage and cached token savings.

Agents SDK usage fields

After Runner.run(...), access usage via result.context_wrapper.usage. Usage is aggregated across all model calls during the run, including calls that produce tool calls or handoffs. With some third-party adapters, usage is not reported by default and needs ModelSettings(include_usage=True).

Gemini CLI token caching

Token caching reuses previous system instructions and context to reduce the number of tokens processed in later requests. It is available with API key authentication (Gemini API key or Vertex AI), not for OAuth users. Use the /stats command to view token usage and cached token savings.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: GitHub repository docs under Apache License 2.0 (https://www.apache.org/licenses/LICENSE-2.0) or MIT License (https://opensource.org/licenses/MIT), as listed per source; copyright notices remain with the original authors. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: OpenAI Agents SDK (Python) docs (GitHub), Usage, MIT (openai/openai-agents-python LICENSE); Google Gemini CLI docs (GitHub), Token caching and cost optimization, Apache-2.0 (google-gemini/gemini-cli LICENSE).

Cite this

Permanent ID: iil:note:nm7b91m7

iinventedlight. 2026. "Tracking agent token usage and cached-token savings." iinventedlight Library, iil:note:nm7b91m7, version of 2026-11-09. https://iinventedlight.com/library/notes/ao-cost-token-usage-tracking/. License: CC-BY-4.0.

@misc{iil_note_nm7b91m7,
  author = {{iinventedlight}},
  title = {{Tracking agent token usage and cached-token savings}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-09},
  url = {https://iinventedlight.com/library/notes/ao-cost-token-usage-tracking/},
  note = {Permanent ID iil:note:nm7b91m7. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/ao-cost-token-usage-tracking.md.