LicenPro
DocumentationREST APIMetering (credit-based & usage-based)

Metering (credit-based & usage-based)

Consume, balance, ledger, grants and per-feature pricing for metered licenses.

Prefix: /api/meter. These routes back the two metered license types — Credit-Based (MeteredToken) and Usage-Based (MeteredCount). Balance is only read and deducted here: validation, activation and session connect never look at it, so a metered license activates happily at zero balance.

Client routes (product API key)

Anonymous with X-API-KEY, called by the SDK on the customer's machine. The API key user must own or belong to the license's product.

POST/api/meter/consume

Deducts from the wallet. Body: licenseKey, featureName, idempotencyKey, optional quantity (default 1), hardwareId, activationId. Credit-Based deducts TokenCost × quantity; Usage-Based deducts quantity. idempotencyKey is required — the server charges (wallet, idempotencyKey) at most once and replays every later call with idempotentReplay: true, which is what makes a retry after a timeout safe. The key is fingerprinted together with feature, quantity and hardwareId: reusing it for a different operation returns IdempotencyConflict (409).

GET/api/meter/balance

Current balance for one license key, without deducting. The key goes in the X-License-Key header so it stays out of URLs that proxies and request logs record; the legacy ?licenseKey= query is still accepted for older SDKs. Returns balance, meteringMode, lowBalanceThreshold and balanceUnitLabel.

Operator routes (JWT)

Dashboard routes. Each one checks that the caller owns the license's product or is an administrator.

GET/api/meter/balance/{licenseId}

Balance for a license by id, for the dashboard rather than the SDK.

GET/api/meter/ledger/{licenseId}

Paginated transaction history (pageNumber, pageSize). Entry types: InitialGrant, Consume (negative), AdminGrant, Adjust.

POST/api/meter/grant

Adds balance. Requires a positive amount and a reason; an optional externalReference (invoice, PO) makes a repeated grant idempotent. There is no payment gateway — top-ups are a manual owner action.

POST/api/meter/adjust

Signed correction or refund: negative amount debits, positive credits. reason is required and a debit cannot push the balance below zero.

PUT/api/meter/balance/{licenseId}/threshold

Sets the low-balance threshold that drives IsLowBalance on the SDK balance result and the dashboard alerts.

GET/api/meter/reconcile/{licenseId}

Recomputes the wallet from its ledger and reports whether the two agree. Read-only.

GET/api/meter/products/{productId}/pricing

Active per-feature token pricing for a product.

PUT/api/meter/features/{featureId}/pricing

Sets TokenCost for one feature (Credit-Based only; must be greater than zero). The previous active row is deactivated and a new one inserted, so history is preserved. Usage-Based ignores pricing entirely. The product Features page edits this inline.

Error codes

Consume returns a machine-readable errorCode alongside the HTTP status. The full table, including which codes are safe to retry, is on the Credit-Based and Usage-Based pages.

Credit-Based licenses · Usage-Based licenses · SDK metering