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

# Create a billable metric

> Defines a new billable metric. A metric specifies the event name, optional filter groups, and aggregation logic that turns raw ingested events into a quantity the billing engine can price against.



## OpenAPI

````yaml /api-reference/v2/specs/2026-04-01.json post /metrics
openapi: 3.1.0
info:
  title: Alguna Public API
  version: '2026-04-01'
servers:
  - url: https://api.alguna.io
security:
  - bearerAuth: []
tags:
  - name: Billing Events and Metrics
  - name: Credit Notes
  - name: Credits
  - name: Customer Portal Sessions
  - name: Customers
  - name: Insights
  - name: Invoices
  - name: Payments
  - name: Plans
  - name: Product Bundles
  - name: Products
  - name: Refunds
  - name: Revenue Schedules
  - name: Subscription Changes
  - name: Subscription Versions
  - name: Subscriptions
  - name: Wallet Grants
  - name: Wallets
paths:
  /metrics:
    post:
      tags:
        - Billing Events and Metrics
      summary: Create a billable metric
      description: >-
        Defines a new billable metric. A metric specifies the event name,
        optional filter groups, and aggregation logic that turns raw ingested
        events into a quantity the billing engine can price against.
      operationId: create-metric
      parameters:
        - in: header
          name: Alguna-Version
          required: true
          schema:
            enum:
              - '2026-04-01'
            type: string
        - in: header
          name: Idempotency-Key
          schema:
            description: >-
              A unique string used to ensure the request is processed exactly
              once. If you retry a request with the same idempotency key within
              24 hours, the original response is returned without re-executing
              the operation.
            example: ik_a1b2c3d4e5f6
            maxLength: 255
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateMetricRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MetricResponse'
          description: Success
          headers:
            Idempotency-Key:
              description: Echo of the idempotency key provided in the request
              schema:
                type: string
            Idempotent-Replayed:
              description: >-
                Whether this response was replayed from a previous request
                (true) or freshly executed (false)
              schema:
                type: boolean
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Bad Request
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Unauthorized
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Not Found
        '409':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: >-
            Conflict — a request with this idempotency key is currently being
            processed
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Unprocessable Entity
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Internal Server Error
components:
  schemas:
    CreateMetricRequest:
      properties:
        aggregation:
          allOf:
            - $ref: '#/components/schemas/AggregationRequest'
          description: How events are aggregated into a metric value
        description:
          description: Description of the metric
          example: Counts API calls per customer
          nullable: true
          type: string
        event_name:
          description: Event name that triggers this metric
          example: api_call
          type: string
        filter_groups:
          description: Filter groups to apply to events before aggregation
          items:
            $ref: '#/components/schemas/FilterGroupRequest'
          type: array
        name:
          description: Name of the metric
          example: API Calls
          type: string
        tag_ids:
          description: Tag identifiers to associate with this metric
          items:
            type: string
          type: array
      required:
        - aggregation
        - event_name
        - name
      type: object
    MetricResponse:
      properties:
        aggregation:
          allOf:
            - $ref: '#/components/schemas/AggregationResponse'
          description: How events are aggregated into a metric value
        created_at:
          description: Timestamp when the metric was created
          example: '2026-04-01T10:00:00Z'
          format: date-time
          type: string
        description:
          description: Description of the metric
          example: Counts API calls per customer
          nullable: true
          type: string
        event_name:
          description: Event name that triggers this metric
          example: api_call
          type: string
        filter_groups:
          description: Filter groups applied to events before aggregation
          items:
            $ref: '#/components/schemas/FilterGroupResponse'
          type: array
        id:
          description: Unique identifier for the metric
          example: mtr_01H1VECT
          type: string
        name:
          description: Name of the metric
          example: API Calls
          type: string
        tag_ids:
          description: Tag identifiers associated with this metric
          items:
            type: string
          type: array
        updated_at:
          description: Timestamp when the metric was last updated
          example: '2026-04-01T12:30:00Z'
          format: date-time
          type: string
      required:
        - aggregation
        - created_at
        - event_name
        - id
        - name
        - updated_at
      type: object
    ErrorResponse:
      properties:
        detail:
          type: string
        status:
          format: int64
          type: integer
      required:
        - status
        - detail
      type: object
    AggregationRequest:
      properties:
        field:
          description: >-
            Event property field to aggregate. Required for all methods except
            count
          example: amount
          type: string
        method:
          description: Aggregation method
          enum:
            - count
            - count_unique
            - average
            - min
            - max
            - sum
          example: sum
          type: string
      required:
        - method
      type: object
    FilterGroupRequest:
      properties:
        filters:
          description: Array of filters in this group
          items:
            $ref: '#/components/schemas/FilterRequest'
          type: array
        operator:
          description: Logical operator combining filters in this group
          enum:
            - and
            - or
          example: and
          type: string
      required:
        - filters
        - operator
      type: object
    AggregationResponse:
      properties:
        field:
          description: Event property field to aggregate. Not required for count method
          example: amount
          type: string
        method:
          description: Aggregation method
          enum:
            - count
            - count_unique
            - average
            - min
            - max
            - sum
          example: sum
          type: string
      required:
        - field
        - method
      type: object
    FilterGroupResponse:
      properties:
        filters:
          description: Array of filters in this group
          items:
            $ref: '#/components/schemas/FilterResponse'
          type: array
        operator:
          description: Logical operator combining filters in this group
          enum:
            - and
            - or
          example: and
          type: string
      required:
        - filters
        - operator
      type: object
    FilterRequest:
      properties:
        field:
          description: Event property field name to filter by
          example: region
          type: string
        operator:
          description: Filter comparison operator
          example: equal
          type: string
        value:
          description: Value to match against
          example: us-east-1
          type: string
      required:
        - field
        - operator
        - value
      type: object
    FilterResponse:
      properties:
        field:
          description: Event property field name
          example: region
          type: string
        operator:
          description: Filter comparison operator
          example: equal
          type: string
        value:
          description: Value to match against
          example: us-east-1
          type: string
      required:
        - field
        - operator
        - value
      type: object
  securitySchemes:
    bearerAuth:
      bearerFormat: API Key
      description: API key authentication. Pass your API key as a Bearer token.
      scheme: bearer
      type: http

````