Skip to main content
POST
/
v1
/
balances.check
Check Balance
curl --request POST \
  --url https://api.example.com/v1/balances.check \
  --header 'Content-Type: application/json' \
  --data '
{
  "customer_id": "<string>",
  "feature_id": "<string>",
  "entity_id": "<string>",
  "required_balance": 123,
  "send_event": true,
  "properties": {},
  "with_preview": true
}
'
{
  "allowed": true,
  "customer_id": "<string>",
  "entity_id": "<string>",
  "required_balance": 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": {}
  },
  "preview": {},
  "error": {
    "message": "<string>",
    "code": "<string>"
  }
}
Checks whether a customer currently has enough balance to use a feature. Optionally combines checking and consuming balance in a single atomic operation.

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
required
The ID of the feature to check access for.
entity_id
string
The ID of the entity for entity-scoped balances (e.g., per-seat limits).
required_balance
number
default:1
Minimum balance required for access. Returns allowed: false if the customer’s balance is below this value.
send_event
boolean
If true, atomically records a usage event while checking access. The required_balance value is used as the usage amount. This combines check + track in one call.
properties
object
Additional properties to attach to the usage event if send_event is true. Accepts any key-value pairs.
with_preview
boolean
If true, includes upgrade/upsell information in the response when access is denied. Useful for displaying paywalls.

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

allowed
boolean
Whether the customer is allowed to use the feature. True if they have sufficient balance or the feature is unlimited/boolean.
customer_id
string
The ID of the customer that was checked.
entity_id
string
The ID of the entity, if an entity-scoped check was performed.
required_balance
number
The required balance that was checked against.
balance
object
The customer’s balance for this feature. Null if the customer has no balance for this feature.
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.
preview
object
Upgrade/upsell information when access is denied. Only present if with_preview was true and allowed is false.

Example Request

Simple Check

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

Check and Consume (Atomic)

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

Example Response

{
  "allowed": true,
  "customer_id": "cus_123",
  "entity_id": null,
  "required_balance": 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
      }
    ]
  }
}

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
  • entity_not_found: The specified entity doesn’t exist
  • insufficient_balance: Customer doesn’t have enough balance (when send_event is true)

Example Error Response

{
  "error": {
    "message": "Customer has insufficient balance",
    "code": "insufficient_balance"
  }
}

Build docs developers (and LLMs) love