utils/billing/billing_utils
library
Enums
-
PrivacyLevel
-
Privacy level controls how much nonessential network traffic and telemetry
the application generates.
Functions
-
calculateCostFromTokens(String model, RawTokenCounts tokens, {required CanonicalNameResolver getCanonicalName, required DefaultModelResolver getDefaultMainLoopModelSetting, required FastModeChecker isFastModeEnabled, UnknownModelCostFlagged? onUnknownModelCost, AnalyticsLogger? logEvent})
→ double
-
Calculate cost from raw token counts without requiring a full TokenUsageInfo
object. Useful for side queries (e.g. classifier) that track token counts
independently.
-
calculateUsdCost(String resolvedModel, TokenUsageInfo usage, {required CanonicalNameResolver getCanonicalName, required DefaultModelResolver getDefaultMainLoopModelSetting, required FastModeChecker isFastModeEnabled, UnknownModelCostFlagged? onUnknownModelCost, AnalyticsLogger? logEvent})
→ double
-
Calculate the cost of a query in US dollars.
If the model's costs are not found, use the default model's costs.
-
countMemoryFileAccessFromEntries(List<TranscriptEntry> entries, {required MemoryFileAccessChecker isMemoryFileAccess})
→ int
-
Count memory file accesses in transcript entries.
Uses the same detection conditions as the PostToolUse session file access
hooks.
-
countUserPromptsFromEntries(List<PromptCountMessage> entries)
→ int
-
Count non-sidechain user messages in transcript entries.
Used to calculate the number of "steers" (user prompts - 1).
-
countUserPromptsInMessages(List<PromptCountMessage> messages)
→ int
-
Count user messages with visible text content in a list of non-sidechain
messages. Excludes tool_result blocks, terminal output, and empty messages.
-
formatModelPricing(ModelCosts costs)
→ String
-
Format model costs as a pricing string for display.
e.g., "$3/$15 per Mtok"
-
getAttributionTexts({required String? userType, required bool isUndercover(), required String getClientType(), required String? remoteSessionId, required String? ingressUrl, required bool isRemoteSessionLocal(String, String?), required String getRemoteSessionUrl(String, String?), required String getMainLoopModel(), required String? getPublicModelDisplayName(String), required String getPublicModelName(String), required bool isInternalModelRepoCached(), required AttributionSettings getInitialSettings(), required bool isDisableCoAuthoredBy()})
→ AttributionTexts
-
Returns attribution text for commits and PRs based on user settings.
-
getEnhancedPrAttribution({required AttributionAppState getAppState(), required String? userType, required bool isUndercover(), required String getClientType(), required String? remoteSessionId, required String? ingressUrl, required bool isRemoteSessionLocal(String, String?), required String getRemoteSessionUrl(String, String?), required AttributionSettings getInitialSettings(), required String getCanonicalName(String), required String getMainLoopModel(), required String sanitizeModelName(String), required Future<bool> isInternalModelRepo(), required Future<AttributionData?> getAttributionData(AttributionAppState), required Future<TranscriptStats> getTranscriptStats()})
→ Future<String>
-
Get enhanced PR attribution text with Neomage contribution stats.
-
getEssentialTrafficOnlyReason()
→ String?
-
Returns the env var name responsible for the current essential-traffic
restriction, or null if unrestricted. Used for user-facing
"unset X to re-enable" messages.
-
getModelCostsForModel(String model, TokenUsageInfo usage, {required CanonicalNameResolver getCanonicalName, required DefaultModelResolver getDefaultMainLoopModelSetting, required FastModeChecker isFastModeEnabled, UnknownModelCostFlagged? onUnknownModelCost, AnalyticsLogger? logEvent})
→ ModelCosts
-
Get the model costs for a model, handling Opus 4.6 fast mode and unknown
models.
-
getModelPricingString(String model, {required CanonicalNameResolver getCanonicalName})
→ String?
-
Get formatted pricing string for a model.
Accepts either a short name or full model name.
Returns null if model is not found.
-
getOpus46CostTier({required bool fastMode, required FastModeChecker isFastModeEnabled})
→ ModelCosts
-
Get the cost tier for Opus 4.6 based on fast mode.
-
getPrAttributionData(AttributionAppState appState, {required Future<AttributionData?> calculateCommitAttribution(List<AttributionState>, List<String>)})
→ Future<AttributionData?>
-
Get full attribution data from the provided AppState's attribution state.
Uses ALL tracked files from the attribution state (not just staged files)
because for PR attribution, files may not be staged yet.
Returns null if no attribution data is available.
-
getPrivacyLevel()
→ PrivacyLevel
-
Get the current privacy level based on environment variables.
-
hasConsoleBillingAccess({required bool isDisableCostWarnings(), required bool isNeomageAiSubscriber(), required AuthTokenSource getAuthTokenSource(), required bool hasApiKey(), required BillingConfig getGlobalConfig()})
→ bool
-
Check if user has Console billing access.
-
hasNeomageAiBillingAccess({required bool isNeomageAiSubscriber(), required SubscriptionType? getSubscriptionType(), required BillingConfig getGlobalConfig()})
→ bool
-
Check if user has Neomage AI billing access.
-
Determines if the current request is billed as extra usage.
-
isEssentialTrafficOnly()
→ bool
-
True when all nonessential network traffic should be suppressed.
Equivalent to the old MAGE_DISABLE_NONESSENTIAL_TRAFFIC check.
-
isTelemetryDisabled()
→ bool
-
True when telemetry/analytics should be suppressed.
True at both noTelemetry and essentialTraffic levels.
-
setMockBillingAccessOverride(bool? value)
→ void
-
Set or clear the mock billing access override.