Guides / track llm cost typescript
How to track LLM cost in TypeScript
Culpa's TypeScript SDK reports calls to a Culpa server, and the default install binds to localhost only. A cloud-hosted app therefore has no route home, so its spend goes unattributed until a relay gives it a mailbox. Culpa, a local-first LLM cost, margin, and forecast ledger, traces every call it receives, and the question worth asking first is which of your calls can reach it.
Why this happens
Local-first is a privacy property and a reachability constraint at the same time. A server bound to localhost can't be reached from a function running on someone else's infrastructure, which describes most production TypeScript. The result is a ledger that looks healthy and describes your development machine. Development traffic is a rounding error against production, so the coverage number is far worse than it feels, and nothing about the ledger itself signals that it's reading a sliver.
What this usually looks like
- Your ledger has data and your production spend is nowhere in it.
- Captured traffic follows your working hours rather than your customers'.
- The features you see are the ones you've been developing, not the ones customers use.
- Captured totals are orders of magnitude below the invoice rather than a few percent below.
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 |
|---|---|---|
| Reading a populated ledger as a covered one. | Development traffic populates a dashboard convincingly while representing almost no spend. | Divide captured spend by the invoice on day one. Coverage is the first number to establish. |
| Assuming a cloud function can reach a local server. | It can't, and the failure is silent because capture fails open by design. | Give cloud workloads a relay, which is a reachable mailbox they can post to. |
| Confusing capture with reach. | You can instrument perfectly and still record nothing if the reports have nowhere to land. | Treat them as two checks. Is the call instrumented, and can the report arrive? |
Run this check tonight
- Divide captured spend by your provider invoice. That single ratio is your coverage.
- Check whether the captured traffic pattern matches your customers' hours or your own.
- List where your code actually runs, and mark which of those can reach your Culpa server.
- Confirm whether a relay is armed for anything running outside your machine.
- Re-check coverage after arming it, and expect the number to move a long way.
A ledger that describes a laptop
Illustrative example
A product running 2 million calls a month in the cloud and 40,000 on a developer machine, on Claude Haiku 4.5 at real rates of $0.001 per 1k input and $0.005 output. Each call sends 2,000 input tokens and returns 300. Volumes are modelled.
Two percent coverage on a dashboard that reads as normal. The failure mode of local-first capture isn't an error message, it's a plausible-looking ledger about the wrong machine.
Every number, with its confidence and source
| Figure | What it means | Confidence | Source |
|---|---|---|---|
| $140 to $7,140 | modelled monthly spend a local-only ledger captures against the full bill | estimated | Both endpoints from the teardown arithmetic at real Claude Haiku 4.5 rates from the price book, effective 2026-07-02. A range because call volumes are modelled. |
| 2% | modelled capture coverage for a cloud-hosted product with no relay armed | calculated | $140 divided by $7,140, from the teardown arithmetic. |
What a generic answer can’t know
Coverage is the ratio between what your ledger holds and what you were billed, and no provider can compute it because it has never seen your ledger. Establishing it takes both numbers in one place. Culpa holds its half on your infrastructure, keeps your prompts and responses there, and counts the calls to run your plan.
Questions founders ask next
Can a Vercel or Lambda function report to a local Culpa?
Not directly, because the default install binds to localhost and a cloud function has no route to it. A relay gives those workloads a reachable mailbox to post to, which the local install then pulls from.
Is this the same thing as the Vercel AI SDK adapter?
No, and the two get confused because both mention Vercel. The adapter is about capturing a call. The relay is about the report reaching you when your code runs somewhere else. A cloud app usually needs both.
How do I know my coverage is bad?
Divide captured spend by the provider invoice for the same period. Anything far below one means calls are being made that never reach your ledger, and a populated dashboard isn't evidence against that.
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: Anthropic pricing. Last reviewed 2026-08-02. Plain text version.