Skip to content

feat!: rename LDAIMetrics.usage and AIGraphMetrics.usage to .tokens#175

Merged
jsonbailey merged 1 commit intomainfrom
jb/align-usage-to-tokens
May 7, 2026
Merged

feat!: rename LDAIMetrics.usage and AIGraphMetrics.usage to .tokens#175
jsonbailey merged 1 commit intomainfrom
jb/align-usage-to-tokens

Conversation

@jsonbailey
Copy link
Copy Markdown
Contributor

@jsonbailey jsonbailey commented May 7, 2026

Summary

Standardizes on tokens as the field name for token usage across all AI metric types, aligning with the canonical spec rename. Renames:

  • LDAIMetrics.usageLDAIMetrics.tokens (runner-level single-model metrics)
  • AIGraphMetrics.usageAIGraphMetrics.tokens (runner-level graph metrics)
  • LDAIMetricSummary.usageLDAIMetricSummary.tokens (managed-layer single-model summary)
  • AIGraphMetricSummary.usageAIGraphMetricSummary.tokens (managed-layer graph summary)

Updates the type definitions in ldai/providers/types.py and ldai/tracker.py, all internal usages across the SDK (tracker.py, managed_agent_graph.py) and provider packages (openai model + agent + agent-graph runners; langchain model + agent + langgraph runners; langgraph callback handler), tests, and README docstrings. The to_dict() serialization key on LDAIMetrics also changes from usage to tokens.

No backward-compat aliases are kept -- these types are part of the in-progress unreleased SDK iteration after PR #173 (the prior rename batch).

Coordinated PRs

This is one of three coordinated PRs landing this rename together:

Test plan

  • make test -- all 325 tests pass (server-ai 196, langchain 85, openai 44)
  • make lint -- mypy, isort, pycodestyle all clean across all three packages
  • e2e validation via hello-python-ai chat-judge example (sibling agent)

Note

Medium Risk
Broad breaking API rename from usage to tokens across SDK/provider metric types and serialization, which will require downstream code updates and could silently drop token tracking if any call sites were missed.

Overview
Standardizes token accounting field names by renaming usagetokens across core metric types (LDAIMetrics, AIGraphMetrics) and their managed summaries, including LDAIMetrics.to_dict() now emitting a tokens key.

Updates all affected runners (LangChain, LangGraph, OpenAI models/agents/graphs), tracker integration (track_tokens, graph total token tracking), docs, and tests to use the new tokens field with no backward-compatible alias.

Reviewed by Cursor Bugbot for commit ccdc00e. Bugbot is set up for automated code reviews on this repo. Configure here.

Standardize on `tokens` as the field name for token usage across all metric
types in the AI SDK to align with the canonical spec. Renames:

- `LDAIMetrics.usage` -> `LDAIMetrics.tokens`
- `AIGraphMetrics.usage` -> `AIGraphMetrics.tokens`
- `LDAIMetricSummary.usage` -> `LDAIMetricSummary.tokens`
- `AIGraphMetricSummary.usage` -> `AIGraphMetricSummary.tokens`

Updates the type definitions, all internal usages across the SDK and
provider packages (openai, langchain), tests, and README docstrings.
The `to_dict()` serialization key for `LDAIMetrics` also changes from
`usage` to `tokens`.

No backward-compat aliases are kept -- these types are part of the
in-progress unreleased SDK iteration after PR #173.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jsonbailey jsonbailey marked this pull request as ready for review May 7, 2026 16:28
@jsonbailey jsonbailey requested a review from a team as a code owner May 7, 2026 16:28
@jsonbailey jsonbailey merged commit d8c4a70 into main May 7, 2026
44 checks passed
@jsonbailey jsonbailey deleted the jb/align-usage-to-tokens branch May 7, 2026 16:37
@github-actions github-actions Bot mentioned this pull request May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants