Tokentifyai.Usagemeter
0.1.1
dotnet add package Tokentifyai.Usagemeter --version 0.1.1
NuGet\Install-Package Tokentifyai.Usagemeter -Version 0.1.1
<PackageReference Include="Tokentifyai.Usagemeter" Version="0.1.1" />
<PackageVersion Include="Tokentifyai.Usagemeter" Version="0.1.1" />
<PackageReference Include="Tokentifyai.Usagemeter" />
paket add Tokentifyai.Usagemeter --version 0.1.1
#r "nuget: Tokentifyai.Usagemeter, 0.1.1"
#:package Tokentifyai.Usagemeter@0.1.1
#addin nuget:?package=Tokentifyai.Usagemeter&version=0.1.1
#tool nuget:?package=Tokentifyai.Usagemeter&version=0.1.1
Tokentify UsageMeter (.NET)
Out-of-band AI API usage metering for .NET. After setup, call your provider’s HTTP API yourself, then record usage with Meter.Track() (explicit tracking, like the PHP SDK).
Install
dotnet add package Tokentifyai.Usagemeter
Setup
1. Environment (API key is global)
Copy .env.example to .env or use User Secrets / environment variables in your host. Keep the API key out of source code.
# .env — required
USAGEMETER_API_KEY=your_ingest_api_key
USAGEMETER_BUCKET=my-bucket
# optional (SDK default if unset)
USAGEMETER_COLLECTOR_URL=http://205.209.126.182:8006
| Variable | Required | Where to set |
|---|---|---|
USAGEMETER_API_KEY |
Yes | Environment / User Secrets |
USAGEMETER_BUCKET |
Yes* | Environment or Init bucket argument |
USAGEMETER_COLLECTOR_URL |
No | Default http://205.209.126.182:8006 |
USAGEMETER_ENVIRONMENT |
No | Default production |
USAGEMETER_APP_NAME |
No | Optional app label on events |
*Bucket: set in the environment or pass to Tokentify.Init().
Aliases: TOKENTIFY_API_KEY, TOKENTIFY_BUCKET, UM_API_KEY, USAGEMETER_TOKEN, COLLECTOR_URL, etc.
2. Initialize
Use Tokentify.Init() (recommended). Requires account_id and user_id in tracking fields.
using Tokentifyai.Usagemeter;
// API key + bucket from environment
Tokentify.Init("my-bucket", new[] { "account_id", "user_id" });
// First run: verify collector + API key
Tokentify.Init("my-bucket", new[] { "account_id", "user_id" }, new InitOptions
{
VerifyConnection = true,
VerifyApiKey = true,
});
// Production (skip checks after first successful setup)
Tokentify.Init("my-bucket", new[] { "account_id", "user_id" }, new InitOptions
{
VerifyConnection = false,
VerifyApiKey = false,
});
| Call | When to use |
|---|---|
VerifyConnection = true |
First run; GET /health |
VerifyApiKey = true |
Default; probes POST /v1/ingest with empty batch |
Call Init before recording usage events.
3. Launch (v0.1.1)
Set environment variables (or User Secrets), then:
using Tokentifyai.Usagemeter;
Tokentify.Init(
Environment.GetEnvironmentVariable("USAGEMETER_BUCKET") ?? "my-bucket",
new[] { "account_id", "user_id" },
new InitOptions { VerifyConnection = false, VerifyApiKey = false });
Meter.Tag(new Dictionary<string, string>
{
["account_id"] = "00000000-0000-4000-8000-000000000001",
["user_id"] = "00000000-0000-4000-8000-000000000002",
});
using var http = new HttpClient();
http.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "YOUR_OPENAI_KEY");
var response = await http.PostAsJsonAsync(
"https://api.openai.com/v1/chat/completions",
new { model = "gpt-4o", messages = new[] { new { role = "user", content = "hi" } } });
Meter.Track(new TrackOptions
{
Provider = "openai",
Model = "gpt-4o",
InputTokens = 10,
OutputTokens = 5,
HttpStatus = (int)response.StatusCode,
Status = response.IsSuccessStatusCode ? "success" : "error",
});
await Meter.FlushAsync();
4. Develop from this repo
cd tokentify-sdk-dotnet
dotnet build
dotnet test
ASP.NET Core — set secrets:
dotnet user-secrets set USAGEMETER_API_KEY your_ingest_api_key
dotnet user-secrets set USAGEMETER_BUCKET my-bucket
Register once at startup:
Tokentify.Init(builder.Configuration["USAGEMETER_BUCKET"]!, new[] { "account_id", "user_id" });
Package naming (aligned with other SDKs)
| Platform | Package |
|---|---|
| Python | tokentifyai-usagemeter |
| PHP (Composer) | tokentifyai/usagemeter |
| Node (npm) | tokentifyai-usagemeter |
| .NET (NuGet) | Tokentifyai.Usagemeter |
Publish to NuGet
- Create account at nuget.org
dotnet pack -c Releasedotnet nuget push bin/Release/Tokentifyai.Usagemeter.0.1.1.nupkg --api-key YOUR_KEY --source https://api.nuget.org/v3/index.json
| 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 |
|---|---|---|
| 0.1.1 | 117 | 6/4/2026 |