Skip to main content

Usage Limits (Credits)

Set usage limits on API keys to cap the total number of requests. Unkey automatically enforces credit-based quotas and blocks excess usage.
3 min read

Usage limits let you set a maximum number of requests a key can make. After the limit is reached, the key becomes invalid until you add more credits or reset it. This is different from rate limiting, which controls frequency, usage limits control total volume.

When to use this#

Pay-per-use APIs

Sell API credits that get consumed with each request. Customer buys 10,000 requests, key stops working at 10,001.

Trial/freemium tiers

Give new users 100 free requests to try your API. They upgrade or stop.

Subscription quotas

"Pro plan includes 50,000 requests/month", combine with auto-refill for recurring limits.

One-time tokens

Create a key that works exactly once, like a single-use download link.

How it works#

  1. Create a key with credits.remaining set to your limit
  2. Each verification decrements the remaining count
  3. When remaining hits 0, verification fails with code: USAGE_EXCEEDED
  4. You can add more credits anytime via the API

Create a key with usage limits#

Verification response#

When you verify a key with usage limits, the response includes the current credit count:

Note

The credits value shows remaining credits after this verification. A value of 999 means the key can be verified 999 more times.

When credits are exhausted:

Custom cost per request#

By default, each verification costs 1 credit. But some operations should cost more, maybe a complex query costs 10 credits while a simple lookup costs 1.

Specify the cost at verification time:

Warning

If the key doesn't have enough remaining credits, the verification fails. A key with 5 remaining credits will reject a request with cost: 10.

Cost of 0 (check without consuming)#

Set cost: 0 to verify a key without consuming any credits. Useful for checking key validity or metadata without affecting the balance.

Add more credits#

When a user purchases more credits or you need to refill manually:

Operations available:

  • set, Set credits to an exact value
  • increment, Add credits to current balance
  • decrement, Subtract credits from current balance

Remove usage limits#

To make a key unlimited again, set credits to null:

Usage limits vs rate limits#

FeatureUsage LimitsRate Limits
What it controlsTotal requests everRequests per time window
Resets automatically?No (unless using refill)Yes, after window expires
Use caseBilling, quotas, trialsAbuse protection, fair usage
Example"1000 requests total""100 requests per minute"

Use both together: Rate limits protect against burst abuse, usage limits enforce billing quotas.

Next steps#