Vercel AI SDK cost tracking

Price every Vercel AI SDK call on any provider with one middleware, streaming included, and attribute it to customers and features.

By Keyveve, Inc. · Updated 2026-10-23

One middleware for AI SDK 5 and 6 prices every generateText, streamText, generateObject and streamObject call, on every provider the AI SDK supports. Streaming calls are priced when the stream finishes, with cached input kept apart.

Install

npm install @veqen/sdk

Wrap the model

import { openai } from "@ai-sdk/openai";
import { generateText, wrapLanguageModel } from "ai";
import { withTags } from "@veqen/sdk";
import { veqen } from "@veqen/sdk/ai-sdk";

const model = wrapLanguageModel({ model: openai("gpt-5-mini"), middleware: veqen({ feature: "chat" }) });

await withTags({ customer: org.id }, () => generateText({ model, prompt }));

Set VEQEN_API_KEY to an ingest key on the server. The provider comes from the AI SDK model: @ai-sdk/azure calls are Azure's bill, @ai-sdk/amazon-bedrock calls Bedrock's.

Already exporting telemetry?

If you turn on experimental_telemetry, you can send those spans to Veqen's OpenTelemetry endpoint instead of adding the middleware. functionId becomes the feature and metadata.customer the customer. See OpenTelemetry. Use one path, not both.

Through the Vercel AI Gateway, the gateway's own reported cost is kept: see the AI Gateway guide.

Next

Veqen records what every AI request cost and who it was for, checks it against your provider bills and prepares the entries for your accounting system. Start free or read the quickstart.