AI SDK 7 Changed usage. Your Token Counts Are Now Wrong
By Nihar Ranjan Das · Tue Sep 29 2026 · 6 min read · 0 views
View as a Web StoryAI#ai agents#llm#typescript#javascript#ai-sdk#vercel-ai-sdk

AI SDK 7 Changed usage. Your Token Counts Are Now Wrong
If a project upgraded to AI SDK 7 and its per-request token costs suddenly look higher than before, nothing is actually costing more. result.usage used to report only the final step's tokens. In AI SDK 7 it reports the running total across every step in a multi-step tool call (Vercel's AI SDK 7 migration guide). No error is thrown. The numbers just mean something different now.
AI SDK is Vercel's TypeScript toolkit for building applications on top of language models, covering text generation, tool calls, and multi-step agent loops. A multi-step tool call is what happens when a model calls a tool, reads the result, and generates more text before returning a final answer. Each of those is a "step." This release changed what counting them means for token usage.
Key Takeaways
result.usagemoved from final-step-only tokens to a running total across all steps; final-step data is now underresult.finalStep.usage.toolCalls,toolResults,content,files,sources, andwarningsat the top level changed the same way.- Nothing throws an error. Dashboards, budget alerts, and per-request cost logs built on the old shape silently report the wrong numbers.
What Changed, Exactly
The property names didn't change; what they mean did. Before AI SDK 7, result.usage reported only the final step of a multi-step run. A separate result.totalUsage field held the sum across every step (the same migration guide's usage section). AI SDK 7 flips that default:
// Before (AI SDK 6)
console.log(result.usage) // final step only
console.log(result.totalUsage) // all steps
// After (AI SDK 7)
console.log(result.finalStep.usage) // final step only
console.log(result.usage) // all steps (now the default)
The same restructuring hit several other top-level fields. content, toolCalls, toolResults, files, sources, and warnings used to reflect the final step only. In AI SDK 7 they aggregate across every step in the run. The final-step-only version of each now lives under result.finalStep (Vercel's breaking-changes reference for this release).
// AI SDK 7: accessing final-step-only data
console.log(result.finalStep.toolCalls) // final step only
console.log(result.toolCalls) // all steps
Why This Breaks Cost Tracking Specifically
A cost dashboard built against result.usage in AI SDK 6 was already reading final-step tokens, so a single-step call looked identical before and after this change. For example, a simple question-and-answer request with no tool calls has exactly one step, and its usage numbers don't move.
The bug only shows up on multi-step agent runs, which are also the runs that cost the most. The silent inflation lands hardest on exactly the calls a team is most likely to be budgeting around. A three-step tool-calling agent that used to report step three's 800 tokens now reports the full run's 2,400 tokens. Nothing on the calling side changed, and no error explains why.
If your logging or billing code reads result.usage.totalTokens and multiplies it by a per-token rate, that number is now the total for the whole run, not the last step. Update it to read result.finalStep.usage if final-step cost was actually what you wanted tracked.
Most of AI SDK 7's breaking changes trace back to one cause: the team's provider specification changed, and every provider package built on it — @ai-sdk/openai, @ai-sdk/anthropic, and the rest — counts as a breaking change when that happens (the AI SDK team's own v7 tracking issue). Most end users only touch streamText, generateText, or useChat, which is why this upgrade reads as "a few call sites changed" rather than "everything changed."
Two Other Breaking Changes in the Same Upgrade
AI SDK 7 requires Node.js 22 or later, since it depends on native APIs unavailable in earlier LTS versions. It also drops CommonJS entirely in favor of ESM-only imports (Vercel's AI SDK 7 changelog entry). A project still calling require('ai') needs to switch to import syntax. It also needs to add "type": "module" to package.json.
Advertisement
// Before
const { generateText } = require('ai')
// After
import { generateText } from 'ai'
Should You Migrate Now?
| Your situation | What happens if you do nothing | What to do |
|---|---|---|
| Single-step calls only (Q&A, no tools) | Usage numbers are unaffected | Migrate on your own schedule |
| Multi-step agent runs with cost tracking | Dashboards silently over-report cost per call | Update usage reads before upgrading, not after |
| Still on Node.js 18 or 20 | AI SDK 7 won't install or run | Upgrade Node.js first, then the SDK |
What to Check After Upgrading
Run a known multi-step test case through the new SDK version and compare result.usage against what your old dashboard reported for the same request. If the numbers roughly match the old totalUsage field rather than the old usage field, the migration worked as intended and your dashboard just needs its field reference updated.
Search your codebase for every place that reads .usage, .toolCalls, .toolResults, .content, .files, .sources, or .warnings directly off a generateText or streamText result. Each one needs a decision: does this call site want the whole run's data, which is now the default, or just the final step's, which now requires .finalStep. Consider a billing webhook that logs result.usage.totalTokens after every request — that's exactly the kind of call site this change silently breaks.
The easiest way to catch every affected call site is to grep for .usage first and work outward from there, since usage is almost always read closer to a billing or logging boundary than tool-call handling is, and those boundaries are where a wrong number actually costs money.
Frequently Asked Questions
Does AI SDK 7 throw an error if I don't update my usage-tracking code?
No. The property still exists and still returns a number, so nothing crashes. The value is simply the sum across all steps instead of the final step alone, which is why this defect surfaces in cost reports rather than in a stack trace.
What is result.finalStep in AI SDK 7?
result.finalStep holds the data that used to live at the top level of the result object before AI SDK 7: the final step's token usage, tool calls, tool results, content, and provider metadata. Reasoning, request, and response data moved there too, though they still work as deprecated aliases at the top level for now.
Do I need to upgrade Node.js before installing AI SDK 7?
Yes, if you're on Node.js 18 or 20. AI SDK 7 requires Node.js 22 or later because it depends on native APIs those earlier LTS versions don't have (Vercel's AI SDK 7 release notes), and it no longer supports CommonJS require() at all.
Will my single-step chatbot be affected by the usage change?
Not in its numbers. A request with exactly one step reports the same token count under either version, since there's only one step's usage to aggregate. The change only matters once a call makes at least one tool call and continues to a further step.
How do I find every place my code depends on the old usage behavior?
Search for .usage, .totalUsage, .toolCalls, .toolResults, .content, .files, .sources, and .warnings wherever your code reads a generateText or streamText result, then check each call site against the before-and-after examples in this guide.
Advertisement
FAQ
Does AI SDK 7 throw an error if I don't update my usage-tracking code?
No. The property still exists and still returns a number, so nothing crashes. The value is simply the sum across all steps instead of the final step alone, which is why this defect surfaces in cost reports rather than in a stack trace.
What is result.finalStep in AI SDK 7?
result.finalStep holds the data that used to live at the top level of the result object before AI SDK 7: the final step's token usage, tool calls, tool results, content, and provider metadata. Reasoning, request, and response data moved there too, though they still work as deprecated aliases at the top level for now.
Do I need to upgrade Node.js before installing AI SDK 7?
Yes, if you're on Node.js 18 or 20. AI SDK 7 requires Node.js 22 or later because it depends on native APIs those earlier LTS versions don't have, and it no longer supports CommonJS require() at all.
Will my single-step chatbot be affected by the usage change?
Not in its numbers. A request with exactly one step reports the same token count under either version, since there's only one step's usage to aggregate. The change only matters once a call makes at least one tool call and continues to a further step.
How do I find every place my code depends on the old usage behavior?
Search for .usage, .totalUsage, .toolCalls, .toolResults, .content, .files, .sources, and .warnings wherever your code reads a generateText or streamText result, then check each call site against the before-and-after examples in this guide.
Comments
Loading…
Sign in to join the conversation.
Related posts

Claude Sonnet 5.5 migration: which changes return a 400
Claude Sonnet 5.5 launched on September 28, 2026 at the same price as Claude Sonnet 5, $2 per million input tokens and $10 per million output tokens. Moving to it is not a model-ID swap. Several
Tue Sep 29 2026 · 6 min read · 0 views

OpenAI shuts off GPT-4, o1 and o4-mini on October 23
OpenAI shuts off GPT-4, GPT-3.5 Turbo, GPT-4 Turbo, o1, o1-pro, o3-mini, o4-mini and several other models on its API on October 23, 2026. That is 24 days away. Any call that names one of those models
Tue Sep 29 2026 · 6 min read · 0 views

Anthropic's Akamai Deal: What It Buys Claude Users
Anthropic signed an $11.6 billion cloud deal with Akamai. Here's what it actually buys — more future capacity, not necessarily fewer outages.
Sun Sep 27 2026 · 4 min read · 2 views