For the complete documentation index, see llms.txt. This page is also available as Markdown.

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 a BreakdownResponse.

  • Consistent Metric Naming:

    • requests instead of apiCalls or count.

    • tokensIn/tokensOut for base model usage.

    • policyTokensIn/policyTokensOut for policy-evaluation overhead.

    • latencyMs for 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 (workspace or repo).

  • 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).

Method
API Reference
Description

GET /v2/stats/storage

Time-series for storage gateway metrics.

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).

Method
API Reference
Description

GET /v2/stats/ai

Time-series for AI gateway metrics.

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.

Method
API Reference
Description

GET /v2/stats/private-chat

Time-series for private-chat metrics.

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.).

Method
API Reference
Description

GET /v2/stats/policies

Time-series of policy violations, alerts, and blocks.

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.

Method
API Reference
Description

GET /v2/stats/credits

Credit consumption/grant time-series.

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

  1. Use the Right Granularity: Don't query a 365d window if you only need yesterday's data. Smaller windows are faster to aggregate.

  2. Leverage Breakdowns for Dashboards: Breakdown endpoints with includeSeries=true are highly optimized for building UI dashboards (like charts with multiple lines representing different models/workspaces).

  3. 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=..., or aiLlmId=....

  4. Use the Client Library: The @flashgatetech/flashgateclient library handles all the complex generic typings for these responses automatically.

Last updated

Was this helpful?