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

# Get usage statistics

> Use when building usage reports or dashboards across events. Supports filters and grouping; defaults to last 7 days if no range provided.



## OpenAPI

````yaml /api-reference/openapi.json post /events/usage
openapi: 3.0.1
info:
  title: Flexprice API
  description: Flexprice API Service
  contact:
    name: API Support
  license:
    name: AGPL-3.0
    url: https://www.gnu.org/licenses/agpl-3.0.html
  version: '1.0'
servers:
  - url: https://us.api.flexprice.io/v1
    description: US Region
  - url: https://api.cloud.flexprice.io/v1
    description: India Region
security: []
paths:
  /events/usage:
    post:
      tags:
        - Events
      summary: Get usage statistics
      description: >-
        Use when building usage reports or dashboards across events. Supports
        filters and grouping; defaults to last 7 days if no range provided.
      operationId: getUsageStatistics
      requestBody:
        description: Request body
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GetUsageRequest'
        required: true
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GetUsageResponse'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/errors.ErrorResponse'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/errors.ErrorResponse'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    GetUsageRequest:
      required:
        - aggregation_type
        - event_name
      type: object
      properties:
        aggregation_type:
          $ref: '#/components/schemas/types.AggregationType'
        billing_anchor:
          type: string
          description: >-
            BillingAnchor enables custom monthly billing periods for usage
            aggregation.


            When to use:

            - WindowSize = "MONTH" AND you need custom monthly periods (not
            calendar months)

            - Subscription billing that doesn't align with calendar months

            - Example: Customer signed up on 15th, so billing periods are 15th
            to 15th


            When NOT to use:

            - WindowSize != "MONTH" (ignored for DAY, HOUR, WEEK, etc.)

            - Standard calendar-based billing (1st to 1st of each month)


            Example values:

            - "2024-03-05T14:30:45.123456789Z" (5th of each month at 2:30:45 PM)

            - "2024-01-15T00:00:00Z" (15th of each month at midnight)

            - "2024-02-29T12:00:00Z" (29th of each month at noon - handles leap
            years)
          example: '2024-03-05T14:30:45.123456789Z'
          format: date-time
        bucket_size:
          $ref: '#/components/schemas/types.WindowSize'
        customer_id:
          type: string
          example: customer456
        end_time:
          type: string
          example: '2024-03-20T00:00:00Z'
          format: date-time
        event_name:
          type: string
          example: api_request
        external_customer_id:
          type: string
          example: customer456
        filters:
          type: object
          additionalProperties:
            type: array
            items:
              type: string
        group_by_property:
          type: string
          description: >-
            GroupByProperty is the property name in event.properties to group by
            before aggregating.

            When set, aggregation is applied per unique value of this property
            within each bucket,

            then the per-group results are summed to produce the bucket total.
        multiplier:
          type: string
        property_name:
          type: string
          description: will be empty/ignored in case of COUNT
          example: request_size
        start_time:
          type: string
          example: '2024-03-13T00:00:00Z'
          format: date-time
        window_size:
          $ref: '#/components/schemas/types.WindowSize'
    GetUsageResponse:
      type: object
      properties:
        event_name:
          type: string
        results:
          type: array
          items:
            $ref: '#/components/schemas/UsageResult'
        type:
          $ref: '#/components/schemas/types.AggregationType'
        value:
          type: number
    errors.ErrorResponse:
      type: object
      properties:
        code:
          type: string
          enum:
            - not_found
            - already_exists
            - version_conflict
            - validation_error
            - invalid_operation
            - permission_denied
            - http_client_error
            - database_error
            - system_error
            - internal_error
            - service_unavailable
        details:
          type: object
          additionalProperties:
            type: object
        http_status_code:
          type: integer
        message:
          type: string
      x-speakeasy-name-override: ErrorResponse
    types.AggregationType:
      type: string
      enum:
        - COUNT
        - SUM
        - AVG
        - COUNT_UNIQUE
        - LATEST
        - SUM_WITH_MULTIPLIER
        - MAX
        - WEIGHTED_SUM
      x-enum-comments:
        AggregationSumWithMultiplier: Sum with a multiplier - [sum(value) * multiplier]
      x-enum-varnames:
        - AggregationCount
        - AggregationSum
        - AggregationAvg
        - AggregationCountUnique
        - AggregationLatest
        - AggregationSumWithMultiplier
        - AggregationMax
        - AggregationWeightedSum
      x-speakeasy-name-override: AggregationType
    types.WindowSize:
      type: string
      enum:
        - MINUTE
        - 15MIN
        - 30MIN
        - HOUR
        - 3HOUR
        - 6HOUR
        - 12HOUR
        - DAY
        - WEEK
        - MONTH
        - MONTH
      x-enum-varnames:
        - WindowSizeMinute
        - WindowSize15Min
        - WindowSize30Min
        - WindowSizeHour
        - WindowSize3Hour
        - WindowSize6Hour
        - WindowSize12Hour
        - WindowSizeDay
        - WindowSizeWeek
        - WindowSizeMonth
        - DefaultWindowSize
      x-speakeasy-name-override: WindowSize
    UsageResult:
      type: object
      properties:
        value:
          type: number
        window_size:
          type: string
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      description: Enter your API key in the format *x-api-key &lt;api-key&gt;**
      name: x-api-key
      in: header

````