Documentation
¶
Overview ¶
Package usage is the Usage Monitor module: a four-view operational cockpit (Now, Trends, Intelligence, Sources) over the Station Usage Monitor v1 API, enforcing strict separation of cost_kind buckets, unknown values as nil (never 0), parent-blocked quota window shading, and server-side key isolation.
Index ¶
- type CompletedPeriodRow
- type InsightRecommendation
- type NextResetItem
- type ResetCalendarEvent
- type SeriesPoint
- type SpendAnomaly
- type SpendByCostKind
- type SpendGroupRow
- type SubscriptionValueRow
- type UsageAccount
- type UsageIntelligencePayload
- type UsageNowPayload
- type UsageSourceItem
- type UsageSourcesPayload
- type UsageTrendsPayload
- type UsageWindowItem
- type UseItOrLoseItEntry
- type WindowForecast
- type WindowSeries
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CompletedPeriodRow ¶
type CompletedPeriodRow struct {
AccountID string `json:"account_id"`
AccountLabel string `json:"account_label"`
Provider string `json:"provider"`
WindowID string `json:"window_id"`
Model string `json:"model,omitempty"`
Group string `json:"group,omitempty"`
PeriodStart string `json:"period_start"`
PeriodEnd string `json:"period_end"`
PeakUsedPercent *float64 `json:"peak_used_percent"`
UsedAtResetPercent *float64 `json:"used_at_reset_percent"`
CapturedPercent *float64 `json:"captured_percent"`
ForfeitedPercent *float64 `json:"forfeited_percent"`
ExhaustedAt string `json:"exhausted_at,omitempty"`
HoursExhausted *float64 `json:"hours_exhausted"`
Rolling bool `json:"rolling,omitempty"`
ParentBlocked bool `json:"parent_blocked,omitempty"`
}
CompletedPeriodRow is a completed period's captured vs forfeited ledger row.
type InsightRecommendation ¶
type InsightRecommendation struct {
ID string `json:"id"`
Kind string `json:"kind"`
Severity string `json:"severity"`
Title string `json:"title"`
Summary string `json:"summary"`
Action string `json:"action,omitempty"`
AccountID string `json:"account_id"`
AccountLabel string `json:"account_label,omitempty"`
Provider string `json:"provider,omitempty"`
WindowID string `json:"window_id,omitempty"`
DedupeKey string `json:"dedupe_key,omitempty"`
Basis map[string]any `json:"basis,omitempty"`
Evidence []string `json:"evidence,omitempty"`
}
InsightRecommendation is one actionable intelligence recommendation with numeric basis & evidence.
type NextResetItem ¶
type NextResetItem struct {
AccountID string `json:"account_id"`
AccountLabel string `json:"account_label"`
Provider string `json:"provider"`
WindowID string `json:"window_id"`
Model string `json:"model,omitempty"`
Group string `json:"group,omitempty"`
Unit string `json:"unit,omitempty"`
Used *float64 `json:"used"`
Limit *float64 `json:"limit"`
Remaining *float64 `json:"remaining"`
ResetsAt string `json:"resets_at"`
SecondsToReset *int64 `json:"seconds_to_reset"`
PartialReset bool `json:"partial_reset,omitempty"`
Rolling bool `json:"rolling,omitempty"`
ParentBlocked bool `json:"parent_blocked,omitempty"`
ResetCreditsAvailable bool `json:"reset_credits_available,omitempty"`
}
NextResetItem is an upcoming window reset in the countdown rail.
type ResetCalendarEvent ¶
type ResetCalendarEvent struct {
ID string `json:"id"`
Kind string `json:"kind"`
AccountID string `json:"account_id"`
AccountLabel string `json:"account_label"`
Provider string `json:"provider"`
WindowID string `json:"window_id,omitempty"`
Model string `json:"model,omitempty"`
Group string `json:"group,omitempty"`
At string `json:"at"`
SecondsUntil *int64 `json:"seconds_until"`
Summary string `json:"summary"`
}
ResetCalendarEvent is an upcoming window reset, reset-credit availability, or sign-in expiry.
type SeriesPoint ¶
type SeriesPoint struct {
At string `json:"at"`
Used *float64 `json:"used"`
Remaining *float64 `json:"remaining"`
MaxUsed *float64 `json:"max_used,omitempty"`
MinRemaining *float64 `json:"min_remaining,omitempty"`
}
SeriesPoint is one time bucket in a window usage/balance series.
type SpendAnomaly ¶
type SpendAnomaly struct {
ID string `json:"id"`
AccountID string `json:"account_id"`
AccountLabel string `json:"account_label"`
Provider string `json:"provider"`
Model string `json:"model,omitempty"`
CostKind string `json:"cost_kind"`
ObservedAt string `json:"observed_at"`
DailySpendUSD *float64 `json:"daily_spend_usd"`
TrailingMedianUSD *float64 `json:"trailing_median_usd"`
ThresholdUSD *float64 `json:"threshold_usd"`
Kind string `json:"kind"`
WindowCausedBy string `json:"window_caused_by,omitempty"`
Summary string `json:"summary"`
}
SpendAnomaly is a daily spend spike or overage-watch alert.
type SpendByCostKind ¶
type SpendByCostKind struct {
CostKind string `json:"cost_kind"`
KnownCostUSD *float64 `json:"known_cost_usd"`
Events int64 `json:"events"`
UnpricedEvents int64 `json:"unpriced_events"`
PartialEvents int64 `json:"partial_events"`
KnownTokens int64 `json:"known_tokens"`
Models []string `json:"models,omitempty"`
}
SpendByCostKind aggregates gateway spend for an account within a single cost_kind. Different cost_kind buckets are never summed together.
type SpendGroupRow ¶
type SpendGroupRow struct {
Bucket string `json:"bucket"`
GroupKey string `json:"group_key"`
Provider string `json:"provider,omitempty"`
Model string `json:"model,omitempty"`
AccountID string `json:"account_id,omitempty"`
CostKind string `json:"cost_kind"`
KnownCostUSD *float64 `json:"known_cost_usd"`
Events int64 `json:"events"`
UnpricedEvents int64 `json:"unpriced_events,omitempty"`
KnownTokens int64 `json:"known_tokens,omitempty"`
}
SpendGroupRow is a spend row strictly tagged with its cost_kind.
type SubscriptionValueRow ¶
type SubscriptionValueRow struct {
AccountID string `json:"account_id"`
AccountLabel string `json:"account_label"`
Provider string `json:"provider"`
Plan string `json:"plan,omitempty"`
MonthlyPriceUSD *float64 `json:"monthly_price_usd"`
BillingDay *int `json:"billing_day"`
UtilizationPercent *float64 `json:"utilization_percent"`
ForfeitedPercent *float64 `json:"forfeited_percent"`
LeftOnTableUSD *float64 `json:"left_on_table_usd"`
HoursExhausted *float64 `json:"hours_exhausted"`
OverageSpendUSD *float64 `json:"overage_spend_usd"`
PlanFit string `json:"plan_fit"`
FitReason string `json:"fit_reason,omitempty"`
PeriodsAnalyzed int `json:"periods_analyzed,omitempty"`
}
SubscriptionValueRow is a subscription's monthly value, utilization, and plan fit analysis.
type UsageAccount ¶
type UsageAccount struct {
ID string `json:"id"`
Provider string `json:"provider"`
Kind string `json:"kind"`
Label string `json:"label"`
Plan string `json:"plan,omitempty"`
Enabled bool `json:"enabled"`
Health string `json:"health"`
Stale bool `json:"stale"`
ObservedAt string `json:"observed_at,omitempty"`
CollectedAt string `json:"collected_at,omitempty"`
SourceID string `json:"source_id,omitempty"`
Collector string `json:"collector,omitempty"`
LatestError string `json:"latest_error,omitempty"`
Attributes map[string]any `json:"attributes,omitempty"`
Windows []UsageWindowItem `json:"windows"`
SpendByCostKind []SpendByCostKind `json:"spend_by_cost_kind,omitempty"`
RunwayDays *float64 `json:"runway_days"`
LowBalance bool `json:"low_balance,omitempty"`
}
UsageAccount is one account in the Usage Monitor Now / Sources payloads.
type UsageIntelligencePayload ¶
type UsageIntelligencePayload struct {
FetchedAt string `json:"fetched_at"`
InsightsSource string `json:"insights_source"`
ResetsSource string `json:"resets_source"`
Recommendations []InsightRecommendation `json:"recommendations"`
Forecasts []WindowForecast `json:"forecasts"`
Anomalies []SpendAnomaly `json:"anomalies"`
SubscriptionValue []SubscriptionValueRow `json:"subscription_value"`
ResetsCalendar []ResetCalendarEvent `json:"resets_calendar"`
}
UsageIntelligencePayload is the response of GET /api/m/usage/intelligence.
type UsageNowPayload ¶
type UsageNowPayload struct {
FetchedAt string `json:"fetched_at"`
Live bool `json:"live"`
Error string `json:"error,omitempty"`
UseItOrLoseIt []UseItOrLoseItEntry `json:"use_it_or_lose_it"`
NextResets []NextResetItem `json:"next_resets"`
Accounts []UsageAccount `json:"accounts"`
Sources []UsageSourceItem `json:"sources"`
}
UsageNowPayload is the response of GET /api/m/usage/now.
type UsageSourceItem ¶
type UsageSourceItem struct {
ID string `json:"id"`
AccountID string `json:"account_id"`
AccountLabel string `json:"account_label,omitempty"`
Provider string `json:"provider,omitempty"`
Collector string `json:"collector"`
Health string `json:"health"`
Stale bool `json:"stale"`
ObservedAt string `json:"observed_at,omitempty"`
CollectedAt string `json:"collected_at,omitempty"`
LatestError string `json:"latest_error,omitempty"`
WindowCount *int `json:"window_count"`
Attributes map[string]any `json:"attributes,omitempty"`
RawURL string `json:"raw_url,omitempty"`
}
UsageSourceItem is one collector source in the Sources view.
type UsageSourcesPayload ¶
type UsageSourcesPayload struct {
FetchedAt string `json:"fetched_at"`
Live bool `json:"live"`
Sources []UsageSourceItem `json:"sources"`
Accounts []UsageAccount `json:"accounts"`
}
UsageSourcesPayload is the response of GET /api/m/usage/sources.
type UsageTrendsPayload ¶
type UsageTrendsPayload struct {
FetchedAt string `json:"fetched_at"`
SeriesSource string `json:"series_source"`
PeriodsSource string `json:"periods_source"`
SpendSource string `json:"spend_source"`
Series []WindowSeries `json:"series"`
Periods []CompletedPeriodRow `json:"periods"`
Spend []SpendGroupRow `json:"spend"`
}
UsageTrendsPayload is the response of GET /api/m/usage/trends.
type UsageWindowItem ¶
type UsageWindowItem struct {
ID string `json:"id"`
Kind string `json:"kind,omitempty"`
Group string `json:"group,omitempty"`
Model string `json:"model,omitempty"`
Unit string `json:"unit,omitempty"`
Used *float64 `json:"used"`
Limit *float64 `json:"limit"`
Remaining *float64 `json:"remaining"`
WindowSeconds *int64 `json:"window_seconds"`
ResetsAt string `json:"resets_at,omitempty"`
Rolling bool `json:"rolling,omitempty"`
PartialReset bool `json:"partial_reset,omitempty"`
ParentBlocked bool `json:"parent_blocked,omitempty"`
BlockedByWindow string `json:"blocked_by_window,omitempty"`
Severity string `json:"severity,omitempty"`
}
UsageWindowItem is one quota, balance, or spend window on an account.
type UseItOrLoseItEntry ¶
type UseItOrLoseItEntry struct {
Rank int `json:"rank"`
Provider string `json:"provider"`
AccountID string `json:"account_id"`
AccountLabel string `json:"account_label"`
BillingType string `json:"billing_type"`
ModelGroup string `json:"model_group"`
WindowID string `json:"window_id"`
Unit string `json:"unit"`
ForfeitablePercent *float64 `json:"forfeitable_percent"`
ResetsAt string `json:"resets_at,omitempty"`
SecondsToReset *int64 `json:"seconds_to_reset"`
ResetKind string `json:"reset_kind,omitempty"`
UrgencyScore *float64 `json:"urgency_score"`
Modalities []string `json:"modalities,omitempty"`
GatewayModels []string `json:"gateway_models,omitempty"`
}
UseItOrLoseItEntry is one ranked expiring subscription window from /v1/capacity.
type WindowForecast ¶
type WindowForecast struct {
AccountID string `json:"account_id"`
AccountLabel string `json:"account_label"`
Provider string `json:"provider"`
WindowID string `json:"window_id"`
Model string `json:"model,omitempty"`
Group string `json:"group,omitempty"`
UsedPercent *float64 `json:"used_percent"`
BurnRatePerHour *float64 `json:"burn_rate_per_hour"`
TypicalBurnPerHour *float64 `json:"typical_burn_per_hour"`
ProjectedAtReset *float64 `json:"projected_at_reset"`
ProjectedExhaustionAt string `json:"projected_exhaustion_at,omitempty"`
WillRunOut bool `json:"will_run_out,omitempty"`
ForfeitForecast *float64 `json:"forfeit_forecast"`
ResetsAt string `json:"resets_at,omitempty"`
SecondsToReset *int64 `json:"seconds_to_reset"`
ParentBlocked bool `json:"parent_blocked,omitempty"`
}
WindowForecast is the projected usage at reset and exhaustion forecast for a window.
type WindowSeries ¶
type WindowSeries struct {
AccountID string `json:"account_id"`
AccountLabel string `json:"account_label"`
Provider string `json:"provider"`
WindowID string `json:"window_id"`
Model string `json:"model,omitempty"`
Group string `json:"group,omitempty"`
Unit string `json:"unit"`
Kind string `json:"kind"`
Step string `json:"step"`
CurrentPeriod []SeriesPoint `json:"current_period"`
PreviousPeriod []SeriesPoint `json:"previous_period,omitempty"`
}
WindowSeries is a per-window curve with current and previous period points.