Skip to main content
Outcome: each customer gets a monthly allowance, heavy operations cost more than light ones, a customer who runs out gets a 402, and a purchased top-up works on the next request. Unkey does the counting.
You need a root key with the permissions listed on this page. Create one in the dashboard under Settings > Root Keys, and pass it as Authorization: Bearer <root key>. See Permission reference for every permission.

Give the key a monthly allowance

credits.remaining is the balance and credits.refill resets it on a schedule. A monthly refill needs a refillDay (in shorter months it runs on the last day). A refill resets the balance to refill.amount rather than adding to it, so unused credits don’t roll over.
10,000 requests a month, reset on the 1st

Charge per operation

Each verification spends credits.cost, 1 by default. Set the cost per operation: a bulk export might cost 50 and a status check 0. A request that fails any other check, such as a rate limit or permission, spends nothing.
src/billing.ts
Return the balance in a header such as X-Credits-Remaining so customers can see it. Analytics records the credits spent per key and identity, so you can build invoices from it.

Sell top-ups and change plans

keys.updateCredits changes the balance and leaves the refill schedule alone. Use increment when a customer buys credits, decrement to take some back, and set for a new balance. set with value: null makes the key unlimited, for example for an enterprise plan with no cap.
To change the monthly allowance, use keys.updateKey with a new credits.refill.amount. It applies at the next refill.
A refill never lowers a balance, but it doesn’t add to one either. If a top-up leaves the customer below their allowance, the next refill wipes it out. If it leaves them above, the refill skips them. To make top-ups always add on top, track them in your own records and re-apply them after the refill day, or sell them as a separate key with no refill.
Last modified on September 29, 2026