ag-ui-protocol / ag-ui-protocol/ag-ui

[Feature]: @ag-ui/claude-agent-sdk: forward modelUsage in the run result envelope

Open
#2,631 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
15.9k
Forks
1.4k
Avg merge
1d 17h
Merged PRs (30d)
163

Description

### Pre-flight Checklist

- [x] I have searched existing issues and this hasn't been requested yet.

### Problem or Motivation

The result envelope (`lastResultData`) built in the `result` branch of
`streamMessages` in `@ag-ui/claude-agent-sdk` copies `usage` and
`total_cost_usd` from the SDK's `SDKResultMessage` but drops
`resultMsg.modelUsage`. That field (`Record`) carries
per-model token counts.

Consumers pricing non-Claude / gateway-routed turns cannot get per-model usage:
the single `total_cost_usd` misprices them, and the aggregate `usage` object does
not distinguish models. The data exists on the SDK result but never reaches the
`RUN_FINISHED` result envelope.

### Proposed Solution

Forward `modelUsage` in the result envelope — a one-line additive change: add
`modelUsage: resultMsg.modelUsage` to the `lastResultData` object, alongside the
already-forwarded `usage` and `total_cost_usd`. Both `SDKResultSuccess` and
`SDKResultError` carry `modelUsage` (camelCase). When the SDK omits it the value
is `undefined`, so there is no behavior change for existing consumers.

### Alternatives Considered

Consumers could re-derive per-model usage from raw SDK messages, but the adapter
already assembles the result envelope and drops only this field; forwarding it is
the natural place and costs one line.

### Additional Context

A PR is opened alongside this issue.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.