Analytics

Query analytics data

Changed on

Execute an analytics query with specified metrics, dimensions, filters, and time range. Custom access requires an organization-scoped key with analytics:view; grouping or filtering by api_key_id or api_key_tag also requires api_keys:view_all, and by user requires org_members:view. Key hash filters resolve only non-deleted ordinary keys. Workspace-scoped keys with base Read Only or Read Write access can query only their own workspace: a workspace filter naming another workspace is refused, legacy rows with no workspace are excluded (including for the default workspace), and possible-cache metrics such as possible_cached_tokens return 400. Management key required.

post/analytics/query

Request

  • Base URL
    https://openrouter.ai/api/v1
  • Auth
    HTTP bearer

Request body

object required
classifier_dimensions, object

Group results by custom classifier tags, breaking down metrics by the specified dimension values. Requires an active classifier on the workspace.

classifier_filters, object

Filter results to generations with specific classifier tag values. Can be combined with classifier_dimensions (must use the same classifier_id) or used independently with standard dimensions.

dimensions, string[]
filters, Filter[]
granularity, string

Time granularity

group_limit, integer

Maximum rows per distinct combination of dimensions. When omitted on time-series queries (granularity + dimensions), auto-computed to avoid truncating time windows. Explicit values override the default and may truncate time buckets if set lower than the number of buckets in the range. Ignored when no dimensions are specified.

limit, integer

Maximum total rows returned. Defaults to 1000. On time-series queries with dimensions and no explicit group_limit, the server may raise this to accommodate the expected number of unique time-bucket/dimension combinations.

metrics, string[] required
order_by, object
time_range, object

Example request

{
  "classifier_dimensions": {
    "classifier_id": "550e8400-e29b-41d4-a716-446655440000",
    "dimension_names": [
      "department"
    ]
  },
  "classifier_filters": {
    "classifier_id": "550e8400-e29b-41d4-a716-446655440000",
    "filters": [
      {
        "field": "department",
        "operator": "eq"
      }
    ]
  },
  "dimensions": [
    "model"
  ],
  "filters": [
    {
      "field": "model",
      "operator": "eq"
    }
  ],
  "granularity": "day",
  "group_limit": 100,
  "metrics": [
    "request_count"
  ],
  "order_by": {
    "field": "request_count"
  },
  "time_range": {
    "end": "2027-12-31T23:59:59Z",
    "start": "2027-12-31T23:59:59Z"
  }
}

Response

Analytics query results

object required
data, object required

Changes

    • breaking

      added the pattern ^[a-zA-Z_][a-zA-Z0-9_]{0,63}$ to the request property classifier_dimensions/dimension_names/items

    • breaking

      the classifier_filters/filters/items request property type changed from object to no type

    • breaking

      the filters/items request property type changed from object to no type

    9 more changes in this revision