Skip to content

Pin and document how to read token usage after consuming a stream #65

Description

@shibayan

Motivation

A caller that logs token usage once per run needs a supported way to read the total after
consuming the stream with for await. stream.finalResponse() already returns it — usage
contents are summed into usageDetails as updates are folded, matching Go, which sums usage
across the response's messages — but nothing pins that path at the agent level, and the
early-termination case is undocumented.

Scope

  • A test that iterates an agent run to completion and asserts usageDetails on the response from
    finalResponse(), using a mock chat client that emits UsageContent.
  • TSDoc noting that a run abandoned partway reports only the usage observed up to that point.

Metadata

Metadata

Assignees

No one assigned

    Labels

    coreUsage: [Issues, PRs], Target: packages/coredocumentationUsage: [Issues, PRs], Target: documentation changesobservabilityUsage: [Issues, PRs], Target: tracing, metrics, and observability

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions