> ## 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 by meter

> Use when showing usage for a specific meter (e.g. dashboard or overage check). Supports time range, filters, and grouping by customer or subscription.



## OpenAPI

````yaml https://swagger.flexprice.io post /events/usage/meter
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
  - url: https://canada.api.flexprice.io/v1
    description: Canada Region
  - url: https://eu.api.flexprice.io/v1
    description: EU Region
security: []
paths:
  /events/usage/meter:
    post:
      tags:
        - Events
      summary: Get usage by meter
      description: >-
        Use when showing usage for a specific meter (e.g. dashboard or overage
        check). Supports time range, filters, and grouping by customer or
        subscription.
      operationId: getUsageByMeter
      requestBody:
        description: Request body
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GetUsageByMeterRequest'
        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'
        '404':
          description: Resource not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/errors.ErrorResponse'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/errors.ErrorResponse'
      security:
        - ApiKeyAuth: []
      x-codeSamples:
        - lang: typescript
          label: TypeScript
          source: |-
            import { Flexprice } from "@flexprice/sdk";

            const flexprice = new Flexprice({
              apiKeyAuth: "<YOUR_API_KEY_HERE>",
            });

            async function run() {
              const result = await flexprice.events.getUsageByMeter({
                billingAnchor: new Date("2024-03-05T14:30:45Z"),
                customerId: "customer456",
                endTime: new Date("2024-12-09T00:00:00Z"),
                externalCustomerId: "user_5",
                meterId: "123",
                startTime: new Date("2024-11-09T00:00:00Z"),
              });

              console.log(result);
            }

            run();
        - lang: go
          label: Go
          source: "package main\n\nimport(\n\t\"context\"\n\tflexprice \"github.com/flexprice/go-sdk/v2\"\n\t\"github.com/flexprice/go-sdk/v2/types\"\n\t\"github.com/flexprice/go-sdk/v2/models/types\"\n\t\"log\"\n)\n\nfunc main() {\n    ctx := context.Background()\n\n    s := flexprice.New(\n        flexprice.WithSecurity(\"<YOUR_API_KEY_HERE>\"),\n    )\n\n    res, err := s.Events.GetUsageByMeter(ctx, types.GetUsageByMeterRequest{\n        BillingAnchor: types.MustNewTimeFromString(\"2024-03-05T14:30:45Z\"),\n        CustomerID: flexprice.Pointer(\"customer456\"),\n        EndTime: types.MustNewTimeFromString(\"2024-12-09T00:00:00Z\"),\n        ExternalCustomerID: flexprice.Pointer(\"user_5\"),\n        MeterID: \"123\",\n        StartTime: types.MustNewTimeFromString(\"2024-11-09T00:00:00Z\"),\n    })\n    if err != nil {\n        log.Fatal(err)\n    }\n    if res.GetUsageResponse != nil {\n        // handle response\n    }\n}"
        - lang: python
          label: Python
          source: |-
            from flexprice import Flexprice
            from flexprice.utils import parse_datetime


            with Flexprice(
                api_key_auth="<YOUR_API_KEY_HERE>",
            ) as f_client:

                res = f_client.events.get_usage_by_meter(meter_id="123", billing_anchor=parse_datetime("2024-03-05T14:30:45Z"), customer_id="customer456", end_time=parse_datetime("2024-12-09T00:00:00Z"), external_customer_id="user_5", start_time=parse_datetime("2024-11-09T00:00:00Z"))

                # Handle response
                print(res)
components:
  schemas:
    GetUsageByMeterRequest:
      required:
        - meter_id
      type: object
      properties:
        billing_anchor:
          type: string
          description: >-
            BillingAnchor enables custom monthly billing periods for meter usage
            aggregation.


            Usage guidelines:

            - Only effective when WindowSize = "MONTH"

            - For other window sizes (DAY, HOUR, WEEK), this field is ignored

            - When nil, uses standard calendar months (1st to 1st)

            - When provided, creates custom monthly periods (e.g., 5th to 5th)


            Common use cases:

            - Subscription billing periods that don't align with calendar months

            - Customer-specific billing cycles (e.g., signed up on 15th)

            - Multi-tenant systems with different billing anchor dates


            Example: If BillingAnchor = "2024-03-05T14:30:45Z" and WindowSize =
            "MONTH":
              - March period: 2024-03-05 14:30:45 to 2024-04-05 14:30:45
              - April period: 2024-04-05 14:30:45 to 2024-05-05 14:30:45
          example: '2024-03-05T14:30:45Z'
          format: date-time
        bucket_size:
          $ref: '#/components/schemas/types.WindowSize'
        customer_id:
          type: string
          example: customer456
        end_time:
          type: string
          example: '2024-12-09T00:00:00Z'
          format: date-time
        external_customer_id:
          type: string
          example: user_5
        filters:
          type: object
          additionalProperties:
            type: array
            items:
              type: string
        meter_id:
          type: string
          example: '123'
        start_time:
          type: string
          example: '2024-11-09T00:00:00Z'
          format: date-time
        timezone:
          type: string
        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:
          $ref: '#/components/schemas/errors.ErrorCode'
        http_status_code:
          type: integer
        message:
          type: string
      x-speakeasy-name-override: ErrorResponse
    types.WindowSize:
      type: string
      enum:
        - MINUTE
        - 15MIN
        - 30MIN
        - HOUR
        - 3HOUR
        - 6HOUR
        - 12HOUR
        - DAY
        - WEEK
        - MONTH
      x-enum-varnames:
        - WindowSizeMinute
        - WindowSize15Min
        - WindowSize30Min
        - WindowSizeHour
        - WindowSize3Hour
        - WindowSize6Hour
        - WindowSize12Hour
        - WindowSizeDay
        - WindowSizeWeek
        - WindowSizeMonth
      x-speakeasy-name-override: WindowSize
    UsageResult:
      type: object
      properties:
        value:
          type: number
        window_size:
          type: string
    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
    errors.ErrorCode:
      type: string
      enum:
        - http_client_error
        - system_error
        - internal_error
        - not_found
        - already_exists
        - version_conflict
        - validation_error
        - invalid_operation
        - permission_denied
        - database_error
        - service_unavailable
        - too_many_requests
        - not_implemented
      x-enum-varnames:
        - ErrCodeHTTPClient
        - ErrCodeSystemError
        - ErrCodeInternalError
        - ErrCodeNotFound
        - ErrCodeAlreadyExists
        - ErrCodeVersionConflict
        - ErrCodeValidation
        - ErrCodeInvalidOperation
        - ErrCodePermissionDenied
        - ErrCodeDatabase
        - ErrCodeServiceUnavailable
        - ErrCodeTooManyRequests
        - ErrCodeNotImplemented
      x-speakeasy-name-override: ErrorCode
  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

````

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