TokensBill.AspNetCore
0.8.1
See the version list below for details.
dotnet add package TokensBill.AspNetCore --version 0.8.1
NuGet\Install-Package TokensBill.AspNetCore -Version 0.8.1
<PackageReference Include="TokensBill.AspNetCore" Version="0.8.1" />
<PackageVersion Include="TokensBill.AspNetCore" Version="0.8.1" />
<PackageReference Include="TokensBill.AspNetCore" />
paket add TokensBill.AspNetCore --version 0.8.1
#r "nuget: TokensBill.AspNetCore, 0.8.1"
#:package TokensBill.AspNetCore@0.8.1
#addin nuget:?package=TokensBill.AspNetCore&version=0.8.1
#tool nuget:?package=TokensBill.AspNetCore&version=0.8.1
TokensBill.AspNetCore
One line. Every AI token tracked. Automatically captures Anthropic / OpenAI / Gemini token usage from your app's outgoing AI calls and streams it to your TokensBill dashboard — so you can see exactly where your AI spend goes.
Install
dotnet add package TokensBill.AspNetCore
Use — one line at startup
builder.Services.AddTokensBill("tl_live_your_project_key");
Add it in Program.cs where you register services. That's it — every AI API call your app makes through HttpClient is now tracked automatically.
Get your project key from TokensBill → your project → Integration.
What it does
- Hooks the
HttpClientfactory pipeline via anIHttpMessageHandlerBuilderFilter. - Reads token counts and cost from the AI provider's response without altering your call.
- Sends the numbers to TokensBill from a background worker.
- Silent-fail by design — it never throws into, blocks, or slows your application. If TokensBill is unreachable, your app is completely unaffected.
Is the key safe to commit?
The tracking key is a label, not a password. It cannot access your AI provider account, read your prompts, or spend money — it only lets your app report usage numbers to your dashboard. You can regenerate it any time from the dashboard.
Options
builder.Services.AddTokensBill("tl_live_...", cfg =>
{
cfg.Environment = "production"; // production | staging | development
cfg.IngestBaseUrl = "https://tokensbill.aiappsjunction.com"; // override the endpoint
});
Prove a model swap before you make it
Every model-swap recommendation ends by telling you to check output quality yourself. Shadow replay does that check — and it tells you what the check will cost before it runs.
using TokensBill;
var plan = TokensBillControl.Verify(services, "ScoreDocument", "gpt-4.1-mini", samples: 50);
Console.WriteLine(plan.Describe());
plan.Start();
verify() runs nothing. It returns a plan:
Replay ScoreDocument against gpt-4.1-mini - 50 samples, 100 provider calls
Estimated cost ~$0.5875 ($0.0118 per sample), based on your measured average of
2,296 input / 650 output tokens for this function.
Hard cap $1.00. Nothing runs until you call `Start()`.
Only Start() arms it. Two steps on purpose: replay spends your money, and the first thing you
see about that should not be the invoice.
After it starts, the next samples calls to that function have their request bodies held in memory.
Each is re-sent to the candidate model on your own credentials, the two answers are compared
inside your process, and only a score is reported: 188 of 200 agreed (94%). It shows up on the
finding in your dashboard.
The cost, precisely. Each sample is two calls — the current model and the candidate — because
comparing a fresh candidate answer against a stale cached one would score the passage of time as a
model difference. The estimate is priced from token counts this process has actually measured for
that function. If it hasn't seen the function yet it says unknown, never $0.00.
maxCostUsd is a hard cap: the run stops before the sample that would exceed it.
Want the exact number first? dryRun: true captures real request bodies, prices the run from them,
and sends nothing to the provider and no verdict to TokensBill.
Your prompts and responses never leave your infrastructure. The verdict payload is counts, two
model names and a comparison method — the TokensBill API has no field that could receive content.
The answers that disagreed stay on your machine (plan.Result.Mismatches) for you to read.
Limits, stated plainly. Comparison is json (parsed, property order ignored) or exact
(trimmed text). Neither can tell you whether two differently-worded paragraphs mean the same thing,
so this is for structured output. Requests using tools or function calling are never replayed —
re-sending one could fire a real action twice — and neither are streaming requests.
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.0 | 160 | 9/1/2026 |
| 1.0.1 | 128 | 8/20/2026 |
| 1.0.0 | 123 | 8/17/2026 |
| 0.8.1 | 124 | 8/12/2026 |
| 0.8.0 | 115 | 8/12/2026 |
| 0.6.0 | 114 | 8/9/2026 |
| 0.5.0 | 124 | 8/7/2026 |
| 0.4.9 | 124 | 7/30/2026 |
| 0.4.8 | 123 | 7/26/2026 |
| 0.4.7 | 120 | 7/23/2026 |
| 0.4.6 | 127 | 7/23/2026 |
| 0.4.5 | 124 | 7/22/2026 |
| 0.4.4 | 131 | 7/22/2026 |
| 0.4.3 | 121 | 7/20/2026 |
| 0.4.2 | 120 | 7/16/2026 |
| 0.4.1 | 121 | 7/12/2026 |
| 0.3.1 | 133 | 7/9/2026 |
| 0.2.1 | 134 | 7/2/2026 |
| 0.2.0 | 127 | 7/2/2026 |
| 0.1.0 | 124 | 7/1/2026 |
0.7.0 — BEHAVIOUR CHANGE: Environment is now DETECTED instead of defaulting to the literal "production". It reads TOKENSBILL_ENVIRONMENT, ASPNETCORE_ENVIRONMENT, DOTNET_ENVIRONMENT, APP_ENV or ENVIRONMENT (first match wins), folds short forms (prod/stg/uat/ci) to canonical names, passes unrecognised labels through unchanged, and reports "unknown" when nothing is set. Setting Environment explicitly still wins. Until now every staging and dev deployment reported its spend as production unless you configured this by hand, which silently broke exactly the prod-vs-non-prod comparisons the dashboard is for. After upgrading, expect non-production apps to start appearing under their real environment; historical events are unchanged. 0.4.8 — TokensBill.AspNetCore became the single SDK for tracking, utility functions (EstimateCost, EstimateTokens, CompareCosts, Deduplicate, RetryWithBudget) and AI functions (Summarize, ExtractJson, Classify, Chat, Embed). The separate TokensBill.AI package was deprecated in favour of it, and its source has now been removed.