Skip to main content
POST
/
v1
/
balances.track
Track Usage
curl --request POST \
  --url https://api.example.com/v1/balances.track \
  --header 'Content-Type: application/json' \
  --data '
{
  "customer_id": "<string>",
  "feature_id": "<string>",
  "event_name": "<string>",
  "entity_id": "<string>",
  "value": 123,
  "properties": {}
}
'
{
  "customer_id": "<string>",
  "entity_id": "<string>",
  "event_name": "<string>",
  "value": 123,
  "balance": {
    "feature_id": "<string>",
    "granted": 123,
    "remaining": 123,
    "usage": 123,
    "unlimited": true,
    "overage_allowed": true,
    "max_purchase": 123,
    "next_reset_at": 123,
    "breakdown": [
      {
        "id": "<string>",
        "plan_id": "<string>",
        "included_grant": 123,
        "prepaid_grant": 123,
        "remaining": 123,
        "usage": 123,
        "unlimited": true,
        "reset": {
          "interval": "<string>",
          "resets_at": 123
        },
        "price": {},
        "expires_at": 123
      }
    ],
    "feature": {}
  },
  "balances": {},
  "error": {
    "message": "<string>",
    "code": "<string>"
  }
}
Records usage for a customer feature and returns updated balances. Use this after an action happens to decrement usage, or send a negative value to credit balance back.

Authentication

Requires a valid API secret key in the Authorization header:
Authorization: Bearer YOUR_SECRET_KEY

Request Body

customer_id
string
required
The ID of the customer.
feature_id
string
The ID of the feature to track usage for. Required if event_name is not provided.
event_name
string
Event name to track usage for. Use instead of feature_id when multiple features should be tracked from a single event. Either feature_id or event_name must be provided.
entity_id
string
The ID of the entity for entity-scoped balances (e.g., per-seat limits).
value
number
default:1
The amount of usage to record. Use negative values to credit balance (e.g., when removing a seat).
properties
object
Additional properties to attach to this usage event. Accepts any key-value pairs.

Query Parameters

skip_cache
boolean
If true, bypasses the cache and fetches fresh data.
expand
string
Comma-separated list of fields to expand. Available options:
  • balance.feature: Include full feature object in the balance response

Response

customer_id
string
The ID of the customer whose usage was tracked.
entity_id
string
The ID of the entity, if entity-scoped tracking was performed.
event_name
string
The event name that was tracked, if event_name was used instead of feature_id.
value
number
The amount of usage that was recorded.
balance
object
The updated balance for the tracked feature. Null if tracking by event_name that affects multiple features.
feature_id
string
The feature ID this balance is for.
granted
number
Total balance granted (included + prepaid).
remaining
number
Remaining balance available for use.
usage
number
Total usage consumed in the current period.
unlimited
boolean
Whether this feature has unlimited usage.
overage_allowed
boolean
Whether usage beyond the granted balance is allowed (with overage charges).
max_purchase
number
Maximum quantity that can be purchased as a top-up, or null for unlimited.
next_reset_at
number
Timestamp when the balance will reset, or null for no reset.
breakdown
array
Detailed breakdown of balance sources when stacking multiple plans or grants.
id
string
The unique identifier for this balance breakdown.
plan_id
string
The plan ID this balance originates from, or null for standalone balances.
included_grant
number
Amount granted from the plan’s included usage.
prepaid_grant
number
Amount granted from prepaid purchases or top-ups.
remaining
number
Remaining balance available for use.
usage
number
Amount consumed in the current period.
unlimited
boolean
Whether this balance has unlimited usage.
reset
object
Reset configuration for this balance, or null if no reset.
interval
string
Reset interval: day, week, month, or year.
resets_at
number
Timestamp when the next reset occurs.
price
object
Pricing configuration if this balance has usage-based pricing.
expires_at
number
Timestamp when this balance expires, or null for no expiration.
feature
object
The full feature object if expand=balance.feature was used.
balances
object
Map of feature_id to updated balance when tracking by event_name affects multiple features. Only present when using event_name.

Example Request

Track by Feature ID

curl -X POST https://api.autumnai.com/v1/balances.track \
  -H "Authorization: Bearer YOUR_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "customer_id": "cus_123",
    "feature_id": "messages",
    "value": 1
  }'

Track by Event Name

curl -X POST https://api.autumnai.com/v1/balances.track \
  -H "Authorization: Bearer YOUR_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "customer_id": "cus_123",
    "event_name": "ai_chat_request",
    "value": 1
  }'

Credit Balance (Negative Value)

curl -X POST https://api.autumnai.com/v1/balances.track \
  -H "Authorization: Bearer YOUR_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "customer_id": "cus_123",
    "feature_id": "seats",
    "value": -1
  }'

Example Response

Single Feature Response

{
  "customer_id": "cus_123",
  "value": 1,
  "balance": {
    "feature_id": "messages",
    "granted": 100,
    "remaining": 72,
    "usage": 28,
    "unlimited": false,
    "overage_allowed": false,
    "max_purchase": null,
    "next_reset_at": 1773851121437,
    "breakdown": [
      {
        "id": "cus_ent_39qmLooixXLAqMywgXywjAz96rV",
        "plan_id": "pro_plan",
        "included_grant": 100,
        "prepaid_grant": 0,
        "remaining": 72,
        "usage": 28,
        "unlimited": false,
        "reset": {
          "interval": "month",
          "resets_at": 1773851121437
        },
        "price": null,
        "expires_at": null
      }
    ]
  }
}

Multi-Feature Response (Event Name)

{
  "customer_id": "cus_123",
  "event_name": "ai_chat_request",
  "value": 1,
  "balance": null,
  "balances": {
    "ai_tokens": {
      "feature_id": "ai_tokens",
      "granted": 1000,
      "remaining": 950,
      "usage": 50,
      "unlimited": false,
      "overage_allowed": true,
      "max_purchase": null,
      "next_reset_at": 1773851121437
    },
    "ai_requests": {
      "feature_id": "ai_requests",
      "granted": 100,
      "remaining": 85,
      "usage": 15,
      "unlimited": false,
      "overage_allowed": false,
      "max_purchase": null,
      "next_reset_at": 1773851121437
    }
  }
}

Error Responses

error
object
message
string
Human-readable error message.
code
string
Machine-readable error code. Common codes:
  • customer_not_found: The specified customer doesn’t exist
  • feature_not_found: The specified feature doesn’t exist
  • invalid_inputs: Request validation failed (e.g., both feature_id and event_name provided)
  • entity_not_found: The specified entity doesn’t exist
  • insufficient_balance: Customer doesn’t have enough balance for the usage amount
  • invalid_event_name: The specified event name is not configured

Example Error Response

{
  "error": {
    "message": "Either feature_id or event_name must be provided",
    "code": "invalid_inputs"
  }
}

Build docs developers (and LLMs) love