> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nx1cloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Native router metrics (role-scoped: own rows vs everything)

> Aggregated metrics over ``router_replay``. An ``nx1_airouter_admin``
sees everything (with per-user and per-team leaderboards) and may narrow
it to one ``user_id`` and/or one ``team`` (realm role); any other
authenticated caller is scoped to their own rows by username.



## OpenAPI

````yaml get /api/airouter/metrics
openapi: 3.1.0
info:
  title: Nx1 AI API
  description: |

    AI API for Nx1 Data Platform Management and Automated Data Tasks.

    Authentication is required via PSK in Authorization header.

    Default PSK is | [ask a friend] |
  version: 0.10.2
servers: []
security: []
paths:
  /api/airouter/metrics:
    get:
      tags:
        - AI Router
      summary: 'Native router metrics (role-scoped: own rows vs everything)'
      description: |-
        Aggregated metrics over ``router_replay``. An ``nx1_airouter_admin``
        sees everything (with per-user and per-team leaderboards) and may narrow
        it to one ``user_id`` and/or one ``team`` (realm role); any other
        authenticated caller is scoped to their own rows by username.
      operationId: get_router_metrics_api_airouter_metrics_get
      parameters:
        - name: range_days
          in: query
          required: false
          schema:
            type: integer
            default: 30
            title: Range Days
        - name: user_id
          in: query
          required: false
          schema:
            anyOf:
              - type: string
                maxLength: 255
              - type: 'null'
            title: User Id
        - name: team
          in: query
          required: false
          schema:
            anyOf:
              - type: string
                maxLength: 255
              - type: 'null'
            title: Team
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RouterMetricsResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - OAuth2AuthorizationCodeBearer: []
        - APIKeyHeader: []
components:
  schemas:
    RouterMetricsResponse:
      properties:
        scope:
          type: string
          enum:
            - user
            - admin
          title: Scope
        range_days:
          type: integer
          title: Range Days
        available:
          type: boolean
          title: Available
          description: False when the metrics warehouse is unreachable.
        message:
          anyOf:
            - type: string
            - type: 'null'
          title: Message
        pricing_available:
          type: boolean
          title: Pricing Available
          description: >-
            False when no model_pricing table exists, so usage is real but every
            spend figure is 0 rather than unknown-but-nonzero.
          default: true
        kpis:
          $ref: '#/components/schemas/MetricKpis'
        by_model:
          items:
            $ref: '#/components/schemas/ModelUsage'
          type: array
          title: By Model
        by_decision:
          items:
            $ref: '#/components/schemas/DecisionUsage'
          type: array
          title: By Decision
        over_time:
          items:
            $ref: '#/components/schemas/TimeBucket'
          type: array
          title: Over Time
        top_users:
          items:
            $ref: '#/components/schemas/UserUsage'
          type: array
          title: Top Users
        top_teams:
          items:
            $ref: '#/components/schemas/TeamUsage'
          type: array
          title: Top Teams
        user_filter:
          anyOf:
            - type: string
            - type: 'null'
          title: User Filter
        team_filter:
          anyOf:
            - type: string
            - type: 'null'
          title: Team Filter
      type: object
      required:
        - scope
        - range_days
        - available
      title: RouterMetricsResponse
      description: Aggregated router metrics, scoped by the caller's role.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    MetricKpis:
      properties:
        requests:
          type: integer
          title: Requests
          default: 0
        total_tokens:
          type: integer
          title: Total Tokens
          default: 0
        prompt_tokens:
          type: integer
          title: Prompt Tokens
          default: 0
        completion_tokens:
          type: integer
          title: Completion Tokens
          default: 0
        est_spend_usd:
          type: number
          title: Est Spend Usd
          default: 0
        blocked:
          type: integer
          title: Blocked
          default: 0
        p95_latency_ms:
          type: number
          title: P95 Latency Ms
          default: 0
        cache_hit_rate:
          type: number
          title: Cache Hit Rate
          default: 0
      type: object
      title: MetricKpis
    ModelUsage:
      properties:
        model:
          type: string
          title: Model
        provider:
          anyOf:
            - type: string
            - type: 'null'
          title: Provider
        requests:
          type: integer
          title: Requests
          default: 0
        total_tokens:
          type: integer
          title: Total Tokens
          default: 0
        est_spend_usd:
          type: number
          title: Est Spend Usd
          default: 0
      type: object
      required:
        - model
      title: ModelUsage
    DecisionUsage:
      properties:
        decision:
          type: string
          title: Decision
        requests:
          type: integer
          title: Requests
          default: 0
        total_tokens:
          type: integer
          title: Total Tokens
          default: 0
      type: object
      required:
        - decision
      title: DecisionUsage
    TimeBucket:
      properties:
        bucket:
          type: string
          title: Bucket
        requests:
          type: integer
          title: Requests
          default: 0
        total_tokens:
          type: integer
          title: Total Tokens
          default: 0
        est_spend_usd:
          type: number
          title: Est Spend Usd
          default: 0
      type: object
      required:
        - bucket
      title: TimeBucket
    UserUsage:
      properties:
        user_id:
          type: string
          title: User Id
        requests:
          type: integer
          title: Requests
          default: 0
        total_tokens:
          type: integer
          title: Total Tokens
          default: 0
        est_spend_usd:
          type: number
          title: Est Spend Usd
          default: 0
      type: object
      required:
        - user_id
      title: UserUsage
    TeamUsage:
      properties:
        team:
          type: string
          title: Team
        requests:
          type: integer
          title: Requests
          default: 0
        total_tokens:
          type: integer
          title: Total Tokens
          default: 0
        est_spend_usd:
          type: number
          title: Est Spend Usd
          default: 0
      type: object
      required:
        - team
      title: TeamUsage
      description: 'Usage by a team: a realm role the caller held.'
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    OAuth2AuthorizationCodeBearer:
      type: oauth2
      flows:
        authorizationCode:
          scopes: {}
          authorizationUrl: >-
            https://sso-rapid.rapid.nx1cloud.com/realms/rapid/protocol/openid-connect/auth
          tokenUrl: >-
            https://sso-rapid.rapid.nx1cloud.com/realms/rapid/protocol/openid-connect/token
    APIKeyHeader:
      type: apiKey
      in: header
      name: Authorization-PSK

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.