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

# Long-format per-user-per-period usage extract

> Aggregates query count and credit usage per `(user, institution, period)` for admin reporting / CSV export. One row per non-zero usage bucket. Capped at 5000 rows; the response sets `truncated: true` when the cap is reached. Excludes histories that the user has flagged as `forgotten`.




## OpenAPI

````yaml /mdx/api-reference/admin/admin-api.json post /api/admin/histories/charts/user-stats
openapi: 3.0.0
info:
  title: Pria Admin API
  version: 2.0.1
  description: >-
    Pria API Documentation Praxis's developer platform is a core part of our
    mission to empower organizations to grow better. Our APIs are designed to
    enable teams of any shape or size to build robust integrations that help
    them customize and get the most value out of Pria. All Pria APIs are built
    using REST conventions and designed to have a predictable URL structure.
    <br/>  <br/>They use many standard HTTP features, including methods (POST,
    GET, PUT, DELETE) and error response codes.  <br/> <br/>All API calls are
    made under https://hiimpria.ai/api and all responses return standard JSON.
    In these docs, you'll find lists of all available endpoints for a given API,
    along with interactive code blocks for building requests. For walkthroughs
    of basic usage for these APIs, check out the API guides.
servers:
  - url: https://pria.praxislxp.com
    description: Pria API Server
security: []
tags:
  - name: Authentication
    description: User authentication, registration, and password management (/api/auth)
  - name: OAuth
    description: OAuth authentication providers - Google, GitHub, SSO (/api/auth/oauth)
  - name: User
    description: User profile management and account operations (/api/user)
  - name: User Institutions
    description: User institution memberships and switching (/api/user/institution)
  - name: User Tools
    description: Available tools for authenticated users (/api/user/tools)
  - name: Institutions
    description: Institution settings and configuration (/api/user/institution)
  - name: Conversation
    description: AI conversation and Q&A endpoints (/api/ai)
  - name: Realtime
    description: Real-time voice AI and WebRTC sessions (/api/ai/rt)
  - name: Assistant
    description: AI assistant configuration and management (/api/user/assistant)
  - name: History
    description: Conversation history and favorites (/api/user/history)
  - name: RAG
    description: >-
      Document upload, embedding, and retrieval-augmented generation
      (/api/user/files, /api/user/rag)
  - name: Setting
    description: Instance variables and settings management (/api/user/setting)
  - name: Branding
    description: Digital twin branding and customization (/api/agent/branding)
  - name: Agent
    description: Agent engagement and session management (/api/agent)
  - name: SDK Launch
    description: >-
      SDK launch token signing and verification for secure iframe embedding
      (/api/auth/sdk-sign, /api/auth/sdk-verify)
  - name: Testing
    description: Health checks, diagnostics, and test endpoints (/api/test)
  - name: Admin Accounts
    description: Account management for super admins (/api/admin/account)
  - name: Admin Institutions
    description: Institution management for admins (/api/admin/institution)
  - name: Admin Users
    description: User management for admins (/api/admin/user)
  - name: Admin Entitlements
    description: >-
      User-institution relationships and permissions
      (/api/admin/userInstitution)
  - name: Admin Sessions
    description: Session management for admins (/api/admin/session)
  - name: Admin Histories
    description: Conversation history management and analytics (/api/admin/history)
  - name: Admin Assistants
    description: AI assistant management for admins (/api/admin/assistant)
  - name: Admin Questions
    description: Institution question and prompt management (/api/admin/question)
  - name: Admin Tools
    description: Tool configuration management (/api/admin/tool)
  - name: Admin AI Models
    description: AI model configuration (/api/admin/aimodel)
  - name: Admin MCP Servers
    description: Model Context Protocol server management (/api/admin/mcpserver)
  - name: Admin Feedbacks
    description: User feedback management (/api/admin/feedback)
  - name: Admin Uploads
    description: Upload management (/api/admin/upload)
  - name: Admin Charts
    description: Analytics and visualization chart management (/api/admin/chart)
  - name: Admin Memory
    description: Admin inspection and editing of user/instance memory parameters.
  - name: Admin Usage Limits
    description: Per-user usage-vs-cap reporting and account-wide at-limit counts.
paths:
  /api/admin/histories/charts/user-stats:
    post:
      tags:
        - Admin Histories
      summary: Long-format per-user-per-period usage extract
      description: >
        Aggregates query count and credit usage per `(user, institution,
        period)` for admin reporting / CSV export. One row per non-zero usage
        bucket. Capped at 5000 rows; the response sets `truncated: true` when
        the cap is reached. Excludes histories that the user has flagged as
        `forgotten`.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UserStatsRequest'
      responses:
        '200':
          description: Successful aggregation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UserStatsResponse'
        '400':
          description: Invalid parameters (e.g. unknown granularity)
        '401':
          description: Unauthorized
        '408':
          description: >-
            Aggregation exceeded the server-side time budget. Response carries
            `code: "aggregation_timeout"`; narrow the filter and retry.
      security:
        - apiKeyAuth: []
components:
  schemas:
    UserStatsRequest:
      type: object
      required:
        - granularity
      properties:
        granularity:
          type: string
          enum:
            - day
            - week
            - month
          description: Bucket size for the period column.
        range:
          type: number
          description: Number of time periods to look back (negative for past).
          example: -7
        daterange:
          type: object
          description: Explicit start/end window. Takes precedence over `range`.
          properties:
            start:
              type: string
              format: date-time
            end:
              type: string
              format: date-time
        account:
          type: string
          description: Space-separated account ids to scope the query.
        institution:
          type: string
          description: Space-separated institution ids to scope the query.
        accountType:
          type: string
          enum:
            - user
            - admin
            - super
        usersearch:
          type: string
          description: Case-insensitive substring matched against email / fname / lname.
    UserStatsResponse:
      type: object
      properties:
        success:
          type: boolean
        granularity:
          type: string
          enum:
            - day
            - week
            - month
        truncated:
          type: boolean
          description: >-
            True when the row count hit the per-request cap (5000). Narrow the
            window for full results.
        windowSource:
          type: string
          enum:
            - daterange
            - range
            - default
          description: >-
            How the date window was derived — explicit `daterange` tuple,
            relative `range` integer, or a granularity-based default applied
            because neither was supplied.
        defaultDaysApplied:
          type: number
          nullable: true
          description: >-
            When `windowSource === "default"`, the number of days included in
            the auto-applied window.
        windowStart:
          type: string
          format: date-time
          description: Inclusive lower bound used for the `created` filter.
        windowEnd:
          type: string
          format: date-time
          description: Exclusive upper bound used for the `created` filter.
        data:
          type: array
          items:
            type: object
            properties:
              user:
                type: string
                description: User ObjectId.
              email:
                type: string
              fname:
                type: string
              lname:
                type: string
              institution:
                type: string
                nullable: true
                description: Institution ObjectId, or null for personal-vault queries.
              instanceName:
                type: string
              aiName:
                type: string
              period:
                type: string
                enum:
                  - day
                  - week
                  - month
              periodStart:
                type: string
                format: date-time
                description: Inclusive bucket boundary (00:00 UTC for `day`).
              queryCount:
                type: number
              creditsUsed:
                type: number
              lifetimeUsed:
                type: number
                description: >-
                  Lifetime credits consumed by this user in this institution
                  (from userInstitution.creditConsumed). Scope is lifetime, not
                  the selected period window.
              capLimit:
                type: number
                nullable: true
                description: >-
                  Effective per-user-institution cap resolved via pickCapTier.
                  null when caps are off or tier is none.
              capSource:
                type: string
                enum:
                  - account
                  - institution
                  - none
                description: >-
                  Which tier owns the cap — account
                  (account.creditCaps.enabled), institution
                  (institution.creditCaps.enabled), or none (caps off).
              capUsedPct:
                type: number
                nullable: true
                description: lifetimeUsed / capLimit. null when capLimit is null.
              atCap:
                type: boolean
                description: True when capLimit is active and lifetimeUsed >= capLimit.
        summary:
          type: object
          description: Aggregate statistics over the distinct users in the result set.
          properties:
            meanCreditsPerUserAccount:
              type: number
              description: >-
                Mean per-institution lifetime credits (creditConsumed) per
                distinct user in the result, deduplicated by user (not a
                cross-institution sum).
            meanCreditsPerUserInstitution:
              type: number
              description: >-
                Mean lifetime credits per distinct (user, institution) pair in
                the result.
            usersAtCap:
              type: integer
              description: Count of distinct user ids where atCap is true.
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: x-access-token
      description: JWT token passed in x-access-token header

````