BillKit/DocsConsole
Usage records

Create usage record

Report usage against a metered subscription.

POST/v1/subscriptions/{subscription_id}/usage_records
Operation create_usage_record·Scope usage_records:write·OpenAPI v1.1.0

Parameters

ParameterDescription
subscription_idstring · pathrequiredId of the subscription, which starts sub_.
quantityintegerrequiredUnits of usage to record, from 1 to 1000000. Between 1 and 1000000.
identifierstring | nulloptionalYour deduplication key, unique within the subscription. Reporting an identifier again returns the first record unchanged instead of recording the usage twice. At most 255 characters.
metadataobject | nulloptionalSet of key-value pairs to store on the record. At most 50 keys.
occurred_atinteger | nulloptionalWhen the usage happened, in Unix seconds. Defaults to now. Must not predate the subscription or be more than five minutes in the future. Between 0 and 253402300799.

Returns

Returns an UsageRecordResponse object.

Errors

StatusCause
400The request was refused (type: invalid_request_error): a required parameter is missing (parameter_missing), one failed validation (parameter_invalid) or is not one the operation takes (parameter_unknown), and param names it.
401No credential, or one that does not authenticate.
402The account is suspended (tenant_suspended), or the payment provider refused a charge or refund the call made (type: payment_error, code: payment_refused).
403Authenticated, but not allowed: missing scope (insufficient_scope), a key of the wrong mode (mode_mismatch), or a refused origin. Needs the usage_records:write scope.
404No such object in this account and mode.
409Conflicts with the object's current state (state_conflict, or a more specific code), or an operation still in flight (operation_pending).
413The request body is larger than the API accepts.
429Rate limited. Retry-After says when to try again.
500Something failed on BillKit's side (type: api_error). Retry with the same Idempotency-Key.
502The payment provider failed or did not answer.
503Temporarily unable to serve. reason says whether the request was attempted.
Request · curl
curl -X POST https://api.billkit.eu/v1/subscriptions/sub_9XKp2vQ1/usage_records \
  -H "Authorization: Bearer $BILLKIT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"quantity":0}'
Request body · every field
{
  "identifier": "string",
  "metadata": {
    "key": "value"
  },
  "occurred_at": 1789392000,
  "quantity": 0
}
Response · 200 OK
{
  "created": 1789392000,
  "id": "ur_9XKp2vQ1",
  "identifier": "string",
  "invoice_id": "inv_9XKp2vQ1",
  "livemode": false,
  "metadata": {
    "key": "value"
  },
  "object": "usage_record",
  "occurred_at": 1789392000,
  "quantity": 0,
  "subscription_id": "sub_9XKp2vQ1",
  "written_off_at": 1789392000
}