Skip to content

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

Open
Luca Forstner (lforst) wants to merge 3 commits into
mainfrom
lforst/dum-e/munich-21ffb87de0
Open

Luca Forstner (lforst) wants to merge 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.

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.

1 participant