V2 Unified Stats API
The V2 Unified Stats API provides comprehensive time-series and breakdown statistics across all gateways and services in the Flashgate Platform. It replaces older statistics endpoints with a consistent, predictable, and fully-typed interface.
Overview
The V2 Stats API unifies reporting across Storage, AI, Private Chat, Policies, and Credits. It uses standardized parameter names, shared data structures, and consistent metric definitions.
Key Characteristics
Unified Parameter Structure: All endpoints share the same core filtering (
scope,id,window,timeBucketSize).Standardized Response Shapes: Every time-series endpoint returns a
TimeSeriesResponse, and every breakdown returns aBreakdownResponse.Consistent Metric Naming:
requestsinstead ofapiCallsorcount.tokensIn/tokensOutfor base model usage.policyTokensIn/policyTokensOutfor policy-evaluation overhead.latencyMsfor weighted-average response times.
Flexible Granularity: Time-series data is automatically bucketed based on the requested
window(e.g., a 24-hour window defaults to 10-minute buckets).Rich Breakdowns: Slice data by various dimensions like workspaces, repositories, models, or users.
Scope and Time Window
All V2 Stats API endpoints require scope and window parameters. id is required for non-org scopes:
scope: The organizational level to query (org,workspace,repo).id: The unique identifier (UUID) for the chosen scope (workspaceorrepo).window: The time range looking backwards from now (e.g.,24h,7d,30d,90d,180d,365d).Optional resource filters can be provided per domain (
apiKeyId,bucketId,model,userId,ruleId,aiLlmId).
V2 Unified Stats API Calls
Storage Gateway Stats
Metrics related to object storage operations (uploads, downloads, requests).
GET /v2/stats/storage/breakdown/{by}
Storage breakdown by dimension (workspaces, repos, buckets, nodes), with resource filters.
GET /v2/stats/storage/breakdown/providers
Detailed storage breakdown including protocol and endpoint.
AI Gateway Stats
Metrics for AI proxy operations (excluding Private Chat usage).
GET /v2/stats/ai/breakdown/{by}
AI breakdown by dimension (workspaces, repos, models, providers, aiConfigs), with resource filters.
Private Chat Stats
Metrics specifically for the Flashgate Private Chat application.
GET /v2/stats/private-chat/breakdown/models
Private chat usage breakdown by AI model.
GET /v2/stats/private-chat/breakdown/users
Private chat usage breakdown by user.
Policies Stats
Metrics for AI Governance and Policy enforcement (DLP, PII redaction, etc.).
GET /v2/stats/policies/tokens
Time-series of token overhead consumed by policy evaluation.
GET /v2/stats/policies/breakdown/{by}
Policy breakdown by rules or users.
Credits Stats
Financial and usage metrics regarding credit consumption and grants.
GET /v2/stats/credits/breakdown/{by}
Credit consumption breakdown by dimension.
Common Use Cases
1. Fetching Organization-Wide Storage Usage Over 30 Days
2. Identifying the Most Expensive AI Models
3. Monitoring Policy Violations
Shared Response Structures
The V2 API relies heavily on two primary response envelopes.
Time-Series Response (TimeSeriesResponse<T>)
Returned by all root-level stats endpoints (e.g., /v2/stats/ai).
Breakdown Response (BreakdownResponse<T>)
Returned by all /breakdown/{by} endpoints. Can optionally include time-series data for each entity if includeSeries=true is passed.
Error Handling
400 Bad Request
Cause: Missing required parameters (like scope, id, or window), or invalid parameter values.
500 Internal Server Error
Cause: Server-side aggregation error or database timeout.
Best Practices
Use the Right Granularity: Don't query a
365dwindow if you only need yesterday's data. Smaller windows are faster to aggregate.Leverage Breakdowns for Dashboards: Breakdown endpoints with
includeSeries=trueare highly optimized for building UI dashboards (like charts with multiple lines representing different models/workspaces).Filter by Resource: If you only care about one specific model, API key, bucket, rule, user, or AI config, use resource filters such as
model=gpt-4,apiKeyId=...,bucketId=...,ruleId=...,userId=..., oraiLlmId=....Use the Client Library: The
@flashgatetech/flashgateclientlibrary handles all the complex generic typings for these responses automatically.
Last updated
Was this helpful?