Skip to content

feat: Fix token metrics with AI SDK middleware - #2497

Merged
Luca Forstner (lforst) merged 3 commits into
mainfrom
lforst/dum-e/munich-21ffb87de0
Sep 18, 2026
Merged

Luca Forstner (lforst) merged 3 commits into
mainfrom
lforst/dum-e/munich-21ffb87de0

Conversation

@lforst

Copy link
Copy Markdown
Member

closes SDK-386

  • Fix missing token and cost metrics when AI SDK providers return nested usage objects. Share normalization between instrumentation and the deprecated BraintrustMiddleware, including cache and reasoning tokens.
  • Add wrapAISDK(model) support for AI SDK 5–7, allowing individual models to be traced alongside the existing SDK-level wrapper. Capture generation and streaming calls, errors, cancellation, and time to first token without duplicating provider spans.
  • Correct Anthropic token totals when reported input usage excludes cached tokens, while preserving totals that already include them.

@lforst
Luca Forstner (lforst) merged commit f6f53a2 into main Sep 18, 2026
57 checks passed
@lforst
Luca Forstner (lforst) deleted the lforst/dum-e/munich-21ffb87de0 branch September 18, 2026 16:06
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