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

# Track usage event

> Track a usage event for a metered feature. Deducts from balance/credits if applicable.

Track a usage event for a metered feature. Deducts from balance/credits if applicable.


## OpenAPI

````yaml /openapi/es/rest/2026-08-27.json post /usage/events
openapi: 3.1.0
info:
  title: Commet API
  version: '2026-08-27'
  description: Billing and payments API for SaaS and AI products.
servers:
  - url: https://commet.co/api/v1
security:
  - ApiKeyAuth: []
tags:
  - name: Test Clock
    description: >-
      Simulate the passage of time in sandbox to test billing flows. Mirrors
      Stripe test clocks: forward-only and sandbox-only.
  - name: Customers
  - name: Subscriptions
  - name: Plans
  - name: Markets
    description: >-
      Reusable country groups for market-specific prices and selectable price
      variants.
  - name: Offers
  - name: Promo Codes
  - name: Features
  - name: Usage
  - name: Seats
  - name: Quota
  - name: Add-ons
  - name: Portal
  - name: Credit Packs
  - name: Plan Groups
  - name: Invoices
  - name: Payments
    description: >-
      One-time payments with no subscription or plan. Charge a customer's saved
      payment method off-session, or create a payment link the customer opens to
      pay. Tax, invoice, and receipt are handled automatically.
  - name: Transactions
  - name: Webhooks
  - name: API Keys
  - name: Payouts
    description: >-
      Withdraw available balance to your bank and manage the payout account
      (verification + destination bank accounts).
  - name: Provisioning
    description: >-
      Take ownership of an organization an agent provisioned headlessly. The
      agent holds the API keys from the start; a human claims the account
      through a claim link.
paths:
  /usage/events:
    post:
      tags:
        - Usage
      summary: Track usage event
      description: >-
        Track a usage event for a metered feature. Deducts from balance/credits
        if applicable.
      operationId: track-usage
      parameters:
        - name: Idempotency-Key
          in: header
          required: false
          description: >-
            Unique key used to safely retry this write for 24 hours without
            applying it twice.
          schema:
            type: string
            minLength: 1
            maxLength: 200
        - name: Commet-Version
          in: header
          required: false
          description: >-
            API version used by this reference. Send this header to select this
            contract explicitly.
          schema:
            type: string
            default: '2026-08-27'
          example: '2026-08-27'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              oneOf:
                - type: object
                  properties:
                    featureCode:
                      type: string
                      minLength: 1
                      maxLength: 50
                      pattern: ^[a-z0-9_]+$
                    customerId:
                      type: string
                      minLength: 1
                      maxLength: 200
                    eventId:
                      type: string
                      minLength: 1
                      maxLength: 200
                    timestamp:
                      type: string
                      format: date-time
                    properties:
                      default: []
                      type: array
                      items:
                        type: object
                        properties:
                          property:
                            type: string
                            minLength: 1
                            maxLength: 100
                          value:
                            type: string
                            minLength: 1
                            maxLength: 1000
                        required:
                          - property
                          - value
                    model:
                      type: string
                      minLength: 1
                      maxLength: 200
                    inputTokens:
                      type: integer
                      minimum: 0
                      maximum: 9007199254740991
                    outputTokens:
                      type: integer
                      minimum: 0
                      maximum: 9007199254740991
                    value:
                      not: {}
                    cacheReadTokens:
                      type: integer
                      minimum: 0
                      maximum: 9007199254740991
                    cacheWriteTokens:
                      type: integer
                      minimum: 0
                      maximum: 9007199254740991
                  required:
                    - featureCode
                    - customerId
                    - model
                    - inputTokens
                    - outputTokens
                  additionalProperties: false
                - type: object
                  properties:
                    featureCode:
                      type: string
                      minLength: 1
                      maxLength: 50
                      pattern: ^[a-z0-9_]+$
                    customerId:
                      type: string
                      minLength: 1
                      maxLength: 200
                    eventId:
                      type: string
                      minLength: 1
                      maxLength: 200
                    timestamp:
                      type: string
                      format: date-time
                    properties:
                      default: []
                      type: array
                      items:
                        type: object
                        properties:
                          property:
                            type: string
                            minLength: 1
                            maxLength: 100
                          value:
                            type: string
                            minLength: 1
                            maxLength: 1000
                        required:
                          - property
                          - value
                    value:
                      default: 1
                      type: number
                      minimum: 0
                    model:
                      not: {}
                    inputTokens:
                      not: {}
                    outputTokens:
                      not: {}
                    cacheReadTokens:
                      not: {}
                    cacheWriteTokens:
                      not: {}
                  required:
                    - featureCode
                    - customerId
                  additionalProperties: false
      responses:
        '201':
          description: Success
          headers:
            X-Request-Id:
              $ref: '#/components/headers/RequestId'
            RateLimit-Limit:
              description: Maximum number of requests allowed in the current window.
              schema:
                type: string
            RateLimit-Remaining:
              description: Requests remaining in the current window.
              schema:
                type: string
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UsageEvent'
              example:
                id: usage_1a2b3c4d
                featureCode: api_calls
                value: 1
                customerId: cus_1a2b3c4d
                eventId: request_123
                ts: '2026-09-07T12:00:00.000Z'
                createdAt: '2026-09-07T12:00:00.000Z'
                properties:
                  - property: endpoint
                    value: /v1/search
                object: usage_event
                livemode: false
        '400':
          description: Bad request
          headers:
            X-Request-Id:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  type: validation_error
                  code: validation_error
                  message: The request contains an invalid parameter.
                  doc_url: >-
                    https://commet.co/docs/api-reference/2026-08-27/errors/validation_error.md
        '401':
          description: Unauthorized
          headers:
            X-Request-Id:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  type: authentication_error
                  code: unauthorized
                  message: A valid API key is required.
                  doc_url: >-
                    https://commet.co/docs/api-reference/2026-08-27/errors/unauthorized.md
        '402':
          description: Payment required
          headers:
            X-Request-Id:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  type: billing_error
                  code: payment_failed
                  message: The payment could not be completed.
                  doc_url: >-
                    https://commet.co/docs/api-reference/2026-08-27/errors/payment_failed.md
        '403':
          description: Forbidden
          headers:
            X-Request-Id:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  type: authentication_error
                  code: forbidden
                  message: You do not have permission to perform this operation.
                  doc_url: >-
                    https://commet.co/docs/api-reference/2026-08-27/errors/forbidden.md
        '404':
          description: Not found
          headers:
            X-Request-Id:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  type: not_found_error
                  code: not_found
                  message: The requested resource was not found.
                  doc_url: >-
                    https://commet.co/docs/api-reference/2026-08-27/errors/not_found.md
        '409':
          description: Conflict
          headers:
            X-Request-Id:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  type: conflict_error
                  code: idempotency_in_progress
                  message: >-
                    A request with this idempotency key is still being
                    processed.
                  doc_url: >-
                    https://commet.co/docs/api-reference/2026-08-27/errors/idempotency_in_progress.md
        '422':
          description: Unprocessable entity
          headers:
            X-Request-Id:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  type: validation_error
                  code: validation_error
                  message: >-
                    The requested operation is not valid for the current
                    configuration.
                  doc_url: >-
                    https://commet.co/docs/api-reference/2026-08-27/errors/validation_error.md
        '429':
          description: Too many requests
          headers:
            X-Request-Id:
              $ref: '#/components/headers/RequestId'
            RateLimit-Limit:
              description: Maximum number of requests allowed in the current window.
              schema:
                type: string
            RateLimit-Remaining:
              description: Requests remaining in the current window.
              schema:
                type: string
            RateLimit-Reset:
              description: Seconds until the rate limit window resets.
              schema:
                type: string
            Retry-After:
              description: Seconds to wait before retrying the request.
              schema:
                type: string
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  type: rate_limit_error
                  code: rate_limited
                  message: >-
                    Too many requests. Retry after the interval specified in the
                    Retry-After header.
                  doc_url: >-
                    https://commet.co/docs/api-reference/2026-08-27/errors/rate_limited.md
        '500':
          description: Internal server error
          headers:
            X-Request-Id:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  type: internal_error
                  code: internal_error
                  message: An unexpected error occurred while processing the request.
                  doc_url: >-
                    https://commet.co/docs/api-reference/2026-08-27/errors/internal_error.md
        '503':
          description: Service unavailable
          headers:
            X-Request-Id:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  type: internal_error
                  code: idempotency_unavailable
                  message: >-
                    Idempotency storage is temporarily unavailable. Retry with
                    the same idempotency key.
                  doc_url: >-
                    https://commet.co/docs/api-reference/2026-08-27/errors/idempotency_unavailable.md
      x-codeSamples:
        - lang: typescript
          label: TypeScript
          source: |-
            import { Commet } from "@commet/node";

            const commet = new Commet({ apiKey: "ck_xxx" });

            const usageEvent = await commet.usage.track({
              featureCode: "api_calls",
              customerId: "user_123",
              model: "example",
              inputTokens: 1,
              outputTokens: 1,
            });
        - lang: python
          label: Python
          source: |-
            from commet import Commet

            commet = Commet("ck_xxx")

            usage_event = commet.usage.track(
                feature_code="api_calls",
                customer_id="user_123",
                model="example",
                input_tokens=1,
                output_tokens=1,
            )
        - lang: go
          label: Go
          source: "client, err := commet.New(\"ck_xxx\")\nif err != nil {\n\tlog.Fatal(err)\n}\nctx := context.Background()\n\nusageEvent, err := client.Usage.Track(ctx, &commet.TrackUsageParams{\n\tFeatureCode: \"api_calls\",\n\tCustomerID: \"user_123\",\n\tModel: func(value string) *string { return &value }(\"example\"),\n\tInputTokens: func(value int) *int { return &value }(1),\n\tOutputTokens: func(value int) *int { return &value }(1),\n})\nif err != nil {\n\tlog.Fatal(err)\n}"
        - lang: java
          label: Java
          source: |-
            import co.commet.Commet;
            import co.commet.params.TrackUsageParams;

            var commet = Commet.builder().apiKey("ck_xxx").build();

            var usageEvent = commet.usage().track(
                TrackUsageParams.builder("api_calls", "user_123").model("example").inputTokens(1L).outputTokens(1L).build()
            );
        - lang: php
          label: PHP
          source: |-
            use Commet\Commet;

            $commet = new Commet('ck_xxx');

            $usageEvent = $commet->usage->track(
                featureCode: 'api_calls',
                customerId: 'user_123',
                model: 'example',
                inputTokens: 1,
                outputTokens: 1,
            );
components:
  headers:
    RequestId:
      description: >-
        Server-generated identifier that correlates this response with Platform
        logs.
      schema:
        type: string
        format: uuid
  schemas:
    UsageEvent:
      type: object
      properties:
        id:
          type: string
        featureCode:
          type: string
        value:
          type: number
        customerId:
          type: string
        eventId:
          anyOf:
            - type: string
            - type: 'null'
        ts:
          type: string
          format: date-time
        createdAt:
          type: string
          format: date-time
        properties:
          type: array
          items:
            type: object
            properties:
              property:
                type: string
              value:
                type: string
            required:
              - property
              - value
            additionalProperties: false
        consumption:
          type: object
          properties:
            model:
              type: string
              enum:
                - credits
                - balance
            deducted:
              type: number
            remaining:
              type: number
            blocked:
              type: boolean
          required:
            - model
            - deducted
            - remaining
            - blocked
          additionalProperties: false
        object:
          type: string
          const: usage_event
        livemode:
          type: boolean
      required:
        - id
        - featureCode
        - value
        - customerId
        - eventId
        - ts
        - createdAt
        - properties
        - object
        - livemode
      additionalProperties: false
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            type:
              type: string
            code:
              type: string
            message:
              type: string
            param:
              type: string
            details: {}
            doc_url:
              type: string
          required:
            - type
            - code
            - message
            - doc_url
          additionalProperties: false
      required:
        - error
      additionalProperties: false
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key

````

## Related topics

- [Métricas y eventos de uso](/docs/es/dashboard-metrics-and-events.md)
- [Manejo de errores](/docs/es/error-handling.md)
- [Cobro por Tokens de IA](/docs/es/ai-token-billing.md)
- [Addons](/docs/es/add-ons.md)
- [usage.recorded](/docs/es/webhooks/usage-recorded.md)


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