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

# Record feature usage

> Record a successful feature action with an idempotent request ID.

Records one successful use of an active feature and charges its current `creditCost`. Send `customerId`, `featureId`, and a unique `request_id` for the logical action. Track checks the balance in a transaction; a successful response includes the remaining `availableCredits`, `chargedCredits`, and `idempotent: false`.

If the network response is lost, retry the **same** customer, feature, and `request_id`. Ledger returns `idempotent: true` and does not charge again. Reusing the same customer and request ID for a different feature returns `409 request_id_conflict`.

An insufficient balance returns `409 insufficient_credits` with `availableCredits` and `creditCost`. This can happen even if an earlier [Check credits](https://docs.integrateledger.com/api-reference/usage/check.md) was allowed, because check does not reserve balance. An unknown customer or archived/unknown feature returns `404`. See [Credits and usage](https://docs.integrateledger.com/credits.md) for the recommended check and track sequence.


## OpenAPI

````yaml openapi.json POST /v1/track
openapi: 3.1.0
info:
  title: Ledger API
  version: 0.1.0
servers:
  - url: https://api.integrateledger.com
    description: Hosted Ledger API
security: []
paths:
  /v1/track:
    post:
      tags:
        - Usage
      summary: Record feature usage
      operationId: trackUsage
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TrackInput'
      responses:
        '200':
          description: Usage recorded or previously recorded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TrackResponse'
        '400':
          description: Invalid input
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TrackError'
        '401':
          description: Invalid Ledger API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TrackError'
        '404':
          description: Customer or feature not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TrackError'
        '409':
          description: Insufficient credits or request ID conflict
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TrackError'
      security:
        - ApiKey: []
      x-codeSamples:
        - lang: bash
          label: cURL
          source: |-
            curl --request POST 'https://api.integrateledger.com/v1/track' \
              -H "Authorization: Bearer $LEDGER_API_KEY" \
              -H 'Content-Type: application/json' \
              --data '{"customerId":"user_123","featureId":"api_call","request_id":"operation_123"}'
        - lang: python
          label: Python SDK (source only)
          source: >-
            import os

            from ledger_sdk import Ledger


            ledger = Ledger(api_key=os.environ["LEDGER_API_KEY"])

            ledger.track_usage(customer_id="user_123", feature_id="api_call",
            request_id="operation_123")
        - lang: typescript
          label: TypeScript SDK (source only)
          source: >-
            import { Ledger } from "@ledger/sdk";


            const ledger = new Ledger({ apiKey: process.env.LEDGER_API_KEY ?? ""
            });

            await ledger.trackUsage({ customerId: "user_123", featureId:
            "api_call", requestId: "operation_123" });
components:
  schemas:
    TrackInput:
      type: object
      properties:
        customerId:
          type: string
          minLength: 1
          maxLength: 255
        featureId:
          type: string
          minLength: 1
          maxLength: 100
        request_id:
          type: string
          minLength: 1
          maxLength: 255
      required:
        - customerId
        - featureId
        - request_id
      additionalProperties: false
    TrackResponse:
      type: object
      properties:
        allowed:
          type: boolean
          const: true
        availableCredits:
          type: integer
          minimum: 0
        chargedCredits:
          type: integer
          exclusiveMinimum: 0
        request_id:
          type: string
        idempotent:
          type: boolean
      required:
        - allowed
        - availableCredits
        - chargedCredits
        - request_id
        - idempotent
    TrackError:
      type: object
      properties:
        error:
          type: string
        availableCredits:
          type: integer
          minimum: 0
        creditCost:
          type: integer
          exclusiveMinimum: 0
      required:
        - error
  securitySchemes:
    ApiKey:
      type: http
      scheme: bearer

````

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