Consumption

Usage metering for credits and usage packs

Consume credits or usage-pack units from your backend with access checks, idempotency keys, and insufficient-usage handling.

Start free in test mode. Go live when you're ready.

Category: Integration Flow4 sections

POST /v1/usage/consume

Usage consumption is for usage_pack entitlements such as credit packs, API call bundles, AI generation credits, or other unit-based products. Send the subject and the number of units to consume from your backend. The operation is atomic.

Keep metering server-side. The browser can request work, but your backend should decide whether access exists, run or accept the protected action, and then consume units with an idempotency key tied to that business event.

Usage consume requestConcrete integration example
HTTP
POST /v1/usage/consume
Authorization: Bearer lz_test_...
Idempotency-Key: usage-user_123-req_987
Content-Type: application/json

{
  "subject_ref": "user_123",
  "units": 100
}
Usage consume successConcrete integration example
JSON
{
  "ok": true,
  "consumed": 100,
  "usage_remaining": 900
}

Errors, retries and idempotency

Reuse the same Idempotency-Key when retrying the same business event. Licenzy uses idempotency to safely replay duplicate delivery of the same consumption request and to reject conflicting reuse.

Insufficient usageConcrete integration example
JSON
HTTP 409 Conflict

{
  "error": "insufficient_usage"
}
  • 409 Conflict with insufficient_usage means there are not enough units left.
  • Use one idempotency key per business event, not per HTTP attempt.
  • Do not send a meter field. The confirmed request body is only subject_ref and units.
Insufficient usage is expected state
Treat insufficient_usage as a normal billing boundary. Your backend can return an upgrade, top-up, or checkout path instead of retrying the same consumption request with a different idempotency key.