What this thread does
Run pnpm list ai @ai-sdk/otel --depth 0 first, then connect feature traces, all-step token usage, and the cost of each Gateway generation.
Do first: inspect that package output and the model expression in the production call: which AI SDK major is installed, and does the call use AI Gateway or a direct provider? Choose the matching branch below; the snippets target AI SDK 7, whose migration guide changes both telemetry registration and usage semantics.
The concrete baseline here is ai 7.0.165, released November 7. Keep your provider packages compatible with that major.
1. Requests complete, but the feature has no production traces
On AI SDK 7.0.165, install @ai-sdk/otel with pnpm add @ai-sdk/otel, configure your OpenTelemetry provider/exporter, and register the SDK integration once at application startup. For Next.js, put registration in instrumentation.ts alongside the provider setup:
import { registerOTel } from '@vercel/otel';
import { registerTelemetry } from 'ai';
import { OpenTelemetry } from '@ai-sdk/otel';
export function register() {
registerOTel({ serviceName: 'support-ai' });
registerTelemetry(new OpenTelemetry());
}
On the feature's existing generateText or streamText call, add:
telemetry: {
functionId: 'support-answer',
recordInputs: false,
recordOutputs: false,
},
The v7 telemetry guide documents registration, automatic event delivery, and the gen_ai.* span format. Per-call telemetry.integrations replaces global integrations for that call, so check for an override if spans disappear selectively.
Check in your trace backend: trigger one feature request and find its agent/model spans, feature identifier, duration, model, and input/output token attributes; confirm prompt/response content is absent. A provider/exporter must actually deliver spans to your backend.
2. Streaming or tool loops make the token total look too small
On AI SDK 7.0.165, use result.usage for the operation total and the final step's usage only when you want the last step. result.totalUsage is deprecated. These meanings differ from AI SDK 6; follow the v7 usage migration.
For an existing streamText result, after consuming its stream through your normal response path:
const usage = await result.usage;
const steps = await result.steps;
console.log({ usage, perStep: steps.map(step => step.usage) });
For generateText, read those properties directly after awaiting the call; result.finalStep.usage is the last-step count. For streamText, await result.finalStep before reading that step's usage. Keep one operation-total record; do not add that total to its constituent step records. The stream result reference documents promise-based usage and automatic stream consumption.
Check: make a request that actually completes more than one model step, then compare each populated token field in the operation total with the step totals. Store missing provider counts as unknown rather than inventing zero. An interrupted stream needs an incomplete status, not an assumed final bill.
3. Token counts exist, but the estimated dollars disagree
On AI SDK 7.0.165, retain usage.inputTokens, usage.outputTokens, usage.inputTokenDetails.noCacheTokens, .cacheReadTokens, .cacheWriteTokens, and usage.outputTokenDetails.reasoningTokens where the provider supplies them. The usage field reference distinguishes these categories; totalTokens alone cannot identify the rates to apply.
Use the exact served model and its provider pricing when building an estimate. Do not charge cached tokens again as ordinary input or add reasoning tokens on top of an output count that already includes them. Keep estimates separate from reported charges, especially for provider-hosted tools. Gateway pricing directs readers to model/provider-specific pricing rather than one universal token rate.
Check: compare one completed request with its provider usage breakdown, including cache writes/reads and any separately billed tool calls. If a category is unavailable, mark the estimate incomplete. For multi-step calls, inspect each step's provider metadata rather than only final-step metadata, as documented in the result reference.
4. You need the cost of each Gateway request, including tool loops
On AI SDK 7.0.165 with AI Gateway, capture each completed model call's generation ID before client-side tools run. Add this callback to your existing call:
onLanguageModelCallEnd({ providerMetadata }) {
const id = providerMetadata?.gateway?.generationId;
if (typeof id === 'string') console.log({ generationId: id });
},
Persist those IDs with your application request identifier. For each distinct ID, use gateway.getGenerationInfo({ id }) from import { gateway } from 'ai' and retain the returned totalCost. The Gateway provider guide documents this lookup and per-model-call capture. One operation can have several generations; final-step metadata alone is insufficient. Do not count the same generation twice. Treat an unfinished or unavailable lookup as pending.
Check: find the request in AI Gateway Logs and compare its model, provider, tokens, and cost with the stored generation. Then open Overview at the same project/time range to compare request counts, token counts, spend, and TTFT. Those scopes and metrics are documented in AI Gateway Observability, updated September 8, 2026. Direct-provider calls need their own provider records.
Evidence and limits
Adriano Tirloni's December 10, 2025 report #11037 documented Anthropic web-search input tokens missing from normalized step usage on AI SDK 6 prereleases. On January 16, he reported the discrepancy gone with ai 6.0.39 and @ai-sdk/anthropic 3.0.15. That is historical evidence for reconciling provider details, not evidence of a current AI SDK 7 defect or a known first fixed release.
Token totals, sampled traces, and provider charges measure different things; a trace view alone is insufficient for a billing ledger. A completed-call callback does not cover a stream that fails before that callback. The Gateway guide also documents early generation-ID capture from streaming chunks for that case. Gateway metrics cover traffic routed through Gateway, and the Usage view has a lookback of at most 36 days. No universal token-to-dollar conversion or latency improvement is promised.
Not for: AI SDK 7 tracing-channel context filtering; see ai-sdk-tracing-channel-context-allowlist
Started from a post by @adriano-tirloni, packaged by the editor. Original post