Guides / track llm cost vercel ai sdk
How to track LLM cost in the Vercel AI SDK
Culpa's Vercel AI SDK adapter is middleware you pass to wrapLanguageModel, and it reports token usage from the SDK's own usage object. It wraps generate calls, and streaming capture stays out of scope for now, so a streaming chat product records only part of its spend. Culpa, a local-first LLM cost, margin, and forecast ledger, meters what the adapter reports and shows the gap against your invoice.
Why this happens
The adapter is honest about what it sees, and a reader deserves the same. It hooks wrapGenerate, reads the SDK's usage object, and handles both the v1 field names and the v2 ones. What it doesn't hook is wrapStream. On a chat product that streams almost every response to the browser, the calls the adapter never sees are the majority of the traffic, so a ledger built on this path alone reads far below the invoice. That's a capture gap rather than a pricing error, and it's fixed by moving the capture point.
What this usually looks like
- Your Culpa totals sit far below the provider invoice and the gap holds steady month to month.
- Most of your product streams responses, and most of your captured calls don't.
- Captured call count is a small fraction of the requests your logs show.
- The shortfall started the day the adapter went in, rather than drifting.
Free, no card, no account
Run the free Cost Leak Scan
It shows your most expensive conversation before you install anything.
Mistakes that cost the most
| Mistake | Why it hurts | Do instead |
|---|---|---|
| Treating adapter coverage as complete without reconciling against the invoice. | A capture gap looks exactly like low spend until somebody compares the two numbers. | Reconcile captured spend against the invoice in the first week, and treat the gap as the finding. |
| Capturing at the framework when the framework can't see streams. | You measure the part of your traffic that matters least on a product built around streaming. | Point the base URL at Culpa instead, which sees every call regardless of how the SDK consumes it. |
| Confusing the Vercel AI SDK adapter with deploying on Vercel. | They're separate problems, and solving one leaves the other open. | Use the adapter for capture and a relay for reach if your app runs in the cloud. |
Run this check tonight
- Count what share of your responses stream. On a chat product it's usually most of them.
- Compare captured call count against your own request logs for the same period.
- Compare captured spend against the provider invoice. The ratio is your coverage.
- Check whether your highest-spend feature is a streaming one.
- Decide whether to move capture to the request path rather than waiting on stream support.
What a streaming product captures through generate-only middleware
Illustrative example
A chat product making 2 million model calls a month on GPT-5.4 at real rates of $0.0025 per 1k input and $0.015 output, each call sending 3,000 input tokens and returning 500. The 82% streaming share is modelled.
The adapter priced every call it saw correctly and saw less than a fifth of them. On a streaming product the capture point matters more than the pricing does.
Every number, with its confidence and source
| Figure | What it means | Confidence | Source |
|---|---|---|---|
| $5,400 to $30,000 | modelled monthly spend captured through generate-only middleware against the real invoice | estimated | Both endpoints from the teardown arithmetic at real GPT-5.4 rates per 1k from the price book, effective 2026-07-02. A range because call volume and the streaming share are modelled. |
| 18% | modelled capture coverage on a product where 82% of responses stream | calculated | 360,000 captured calls divided by 2,000,000 total, from the teardown arithmetic. |
What a generic answer can’t know
No provider can tell you which of your calls streamed, because every one of them looks the same from its side. Coverage is the ratio between what your capture path saw and what you were billed for, and only you hold both halves. Culpa keeps them on your infrastructure, where your prompts and responses stay, and counts the calls to run your plan.
Questions founders ask next
Does Culpa's Vercel AI SDK adapter capture streamed responses?
Not yet. The middleware wraps generate calls, and stream capture is deliberately out of scope for the current release. If most of your traffic streams, point your base URL at Culpa instead so capture happens on the request path.
Will the adapter break my app if Culpa is down?
No. It fails open by contract. Reporting rides a call that never throws, and a failed generate is recorded while your own error is rethrown untouched, so a Culpa problem stays a Culpa problem.
Does the adapter import the ai package?
No, it's duck-typed and never imports it. That keeps your dependency tree unchanged and means a version bump in the SDK can't break the adapter through a type mismatch.
On your infrastructure
Culpa runs on your infrastructure. Your prompts and responses never leave it. Culpa counts calls to run your plan, and it fails open, so if it ever breaks your app keeps running.
How Culpa works
Find the culprit. Not just the total.
Your dashboard shows what you spent. It stops short of who spent it. Culpa shows the conversation, the user and the feature behind it.
Your prompts stay local.
Culpa runs on your own infrastructure. What you send to a model reaches us at no point.
Every dollar has a name.
Follow any charge to the conversation, the user, the feature and the customer behind it.
See the bill before it lands.
Cost your next feature before you ship it. You get the likely bill and the worst case, at best, median, p90 and p99.
Three steps to your first answer.
Change one base URL.
Or drop in the Python or TypeScript library.
Find your most expensive conversation.
In the first session, not the first week.
Cost your next feature before you ship it.
Why the bill went up
Example dashboardCalls traced
418,209
across 3 projects
Spend this week
$378.41
+ $182 vs last week
Failed calls
312
74% retried, and you paid for all of them
+ $182 this week traced to one culprit
Spend over 14 days
Most expensive users
Next week forecast
Graded against reality. Accuracy shown as results land.
Free, no card, no account
Run the free Cost Leak Scan
It shows your most expensive conversation before you install anything.
Keep reading
Sources: OpenAI API pricing. Last reviewed 2026-08-02. Plain text version.