Repository navigation
feat(server-utils): Record Vercel AI Gateway cost on AI SDK spans - #26462
Merged
Merged
Conversation
Co-Authored-By: Francesco Gringl-Novy <2411343+mydea@users.noreply.github.com>
Contributor
size-limit report 📦Compared: 557eec5 (PR test merge using develop at 93949c4) Against: 93949c4 (develop) · base run #66413 ✅ Baseline matches: this diff contains only this PR's changes.
|
mydea
marked this pull request as ready for review
November 17, 2026 11:02
javascript-sdk-gitflow
Bot
requested review from
RulaKhaled,
andreiborza and
timfish
November 17, 2026 11:03
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 7bd3c50. Configure here.
Contributor
Optional E2E testsSome optional checks were not successful. They do not block the merge. 1 not successful, 60 successful. See the run.
Successful checks
|
…eway-cost # Conflicts: # dev-packages/node-integration-tests/suites/tracing/vercelai/v6_v7/suite.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What
vercelAIIntegrationrecords the cost that Vercel AI Gateway reports inproviderMetadata.gateway.costasgen_ai.cost.total_tokens. It is recorded ongenerate_content, embedding (embed), rerank, and decide spans.Why
The gateway returns the billed cost of each call, but the integration recorded only tokens. Without this, apps that route through the gateway have to compute cost themselves.
providerMetadatadescribes only one provider call. OngenerateText,streamText,generateObject, andstreamObject, that is the last step. Theirgenerate_contentchild spans already carry the cost of each call, so theinvoke_agentspan gets no cost.embedManymerges metadata across chunks, so a later chunk overwrites the cost. Its span gets no cost, because that value can be partial.Noticed this in junior, where we need to manually collect this together.
via @mydea.
--
View Session [Sentry]