Individual skill

crestapps-core-ai-usage-metering

Skill for AI usage metering in CrestApps.Core 2.0. Covers how every client created by IAIClientFactory (chat, embedding, image, speech-to-text, text-to-speech and realtime) records one AICompletionUsageRecord per provider request, enabling it with GeneralAIOptions EnableAIUsageTracking, the recorded units (cached, reasoning and audio tokens, audio duration, characters, images) and AIUsageOperationTypes, labeling requests by category and purpose with UseUsageLabels, AIUsageScope, AICompletionContextKeys and AIUsagePurposes, metering clients built outside the factory with AIUsageMetering Meter, observing records with IAICompletionUsageObserver, storing them with IAICompletionUsageStore, and building per-model, per-category and per-purpose reports with AIUsageReport. Use it when pricing or attributing AI usage, building a usage dashboard, or troubleshooting missing or mislabeled usage records.

src/CrestApps.AgentSkills/crestapps-core/crestapps-core-ai-usage-metering/SKILL.md

Read pinned source

Source commit d86d04f234b1b2bd8145368a2544490f9d557596

What was checked

Matches the observed repository HEAD
Yes
Scanner rules are current
Yes
Repository scan complete
No
Skill scan complete
Yes
Observed behavior
Instructions only
Last checked
Nov 6, 2026

These are observations at the recorded commit, not a guarantee of safety. Review the source before running it.

Install this skill

Choose an agent in your Stack or copy a command below. Commands fetch the pinned commit and copy only this skill directory. Existing destinations are refused. Copying a command does not install anything.

An install command is unavailable: current rules, complete repository and skill scans, an eligible behavior level and a permitted license are required.

Repository context

Repository stars (not skill ratings)
13
Repository last updated
Oct 21, 2026
License
MIT

Observed agent integration: No specific integration evidence. Standard SKILL.md installation does not imply verified compatibility.

Files and excerpt

File metadata and permitted, redacted excerpts come from the recorded scan. Source links are pinned to that commit.

Browse files
Read excerpt

# CrestApps.Core AI Usage Metering

Every client `IAIClientFactory` returns meters its own requests by wrapping the provider's client and reading the provider-agnostic `UsageDetails` on each response. That covers every provider, including custom `IAIClientProvider` implementations, with no provider code.

## Guidelines

- Turn metering on with `GeneralAIOptions.EnableAIUsageTracking = true`. It is off by default.
- A record is written per request sent to the provider, not per user turn. Planning, query rewrites, vision calls, each tool-calling round trip, each embedding batch and each realtime response are separate records, so the request count equals billed requests.
- Metering sits below every middleware you add, so `UseFunctionInvocation()` yields one record per round trip and a cached response yields none.
- Label your own requests with `UseUsageLabels(...)` on the client pipeline, or an `AIUsageScope` around a call into a service that creates the client for you. Labels never reach the provider.
- A client you build without the factory is not metered until you wrap it with `AIUsageMetering.Meter(...)`.

## Enable Metering and Storage