llm_meter library
llm_meter — Per-request token cost + latency + cache observability for any Flutter LLM app. Drop-in wrapper, live HUD in dev, silent telemetry sink in prod.
Classes
- BatchingSink
- Wraps another MeterSink and flushes events in batches.
- ConsoleSink
- Prints every event with debugPrint (no-op in release unless printInRelease is set).
- Currency
- Currency that costs can be displayed in. USD is the canonical unit costs are recorded in; everything else is converted at display time.
- LlmMeter
- The meter singleton.
- LlmMeterHud
- Drop-in widget that overlays a small floating card showing the live cost, latency, and cache stats reported by LlmMeter.
- MeterConfig
- One-line setup passed to LlmMeter.init.
- MeteredCall
- Wrap any LLM Future + extractor so the meter records it automatically.
- MeteredStream
-
Wraps a
Stream<C>of LLM chunks so the meter records the full call once the stream completes. - MeterEvent
- Immutable record of a single LLM API call.
- MeterSink
- Receives every MeterEvent that the meter records.
- MeterStats
- Snapshot of stats computed over the events currently held by LlmMeter.
- MeterUsage
- Token usage extracted from a provider response.
- MixpanelSink
-
Sends events to Mixpanel's
/trackingestion endpoint. - ModelPricing
- Per-token price for a single model variant, expressed in USD per token.
- ModelStats
- Per-model summary.
- PosthogSink
-
Send events to PostHog's
/capture/endpoint via plain HTTP. - RetryingSink
- Wraps another MeterSink and retries on failure.
-
RingBuffer<
T> - Fixed-capacity, O(1) push ring buffer. Drops the oldest entry when full.
Enums
- HudCorner
- Corner anchor for the HUD card.
- SymbolPosition
- Whether the currency symbol prints before or after the number.
Constants
- defaultPricing → const ModelPricing
- Fallback when a model id is unknown to both the built-in table and any user overrides.
Properties
-
builtInModels
→ List<
String> -
The set of model ids known to the built-in pricing table.
no setter
Functions
-
anthropicUsage(
Map< String, Object?> response) → MeterUsage -
Anthropic Messages API usage shape:
{ usage: { input_tokens, output_tokens, cache_read_input_tokens, cache_creation_input_tokens } }. -
gdprScrub(
MeterEvent event) → MeterEvent -
Redacts user-correlatable fields from
eventfor GDPR-safe transmission. -
geminiUsage(
Map< String, Object?> response) → MeterUsage -
Google Gemini
generateContentusage shape:{ usageMetadata: { promptTokenCount, candidatesTokenCount, cachedContentTokenCount } }. -
openAiUsage(
Map< String, Object?> response) → MeterUsage -
OpenAI Chat Completions / Responses API usage shape:
{ usage: { prompt_tokens, completion_tokens, prompt_tokens_details: { cached_tokens } } }. -
priceForModel(
{required String model, required int tokensIn, required int tokensOut, int cachedTokensIn = 0, Map< String, ModelPricing> ? overrides}) → double - Pure cost calculation. Use this when you want a one-shot quote without recording an event.
-
pricingFor(
String model, {Map< String, ModelPricing> ? overrides}) → ModelPricing -
Lookup the bundled ModelPricing for
model.
Typedefs
-
ChunkUsageExtractor<
C> = MeterUsage? Function(C chunk) - Signature for accumulating per-chunk usage info during a stream.
-
UsageExtractor<
T> = MeterUsage Function(T response) - Signature for converting a provider response into a MeterUsage.