Skip to main content
Usage limits control the total number of requests an API key can make. Unlike rate limits (which control request frequency), usage limits enforce quotas over a key’s lifetime. Combined with automatic refills, they enable subscription models, pay-as-you-go billing, and trial tiers.

Credits system

Unkey’s credits system tracks how many requests a key has remaining:
  • Create a key with credits — Set credits.remaining to the initial quota
  • Each verification consumes credits — By default, 1 credit per request
  • Custom costs — Charge different amounts for different operations
  • Key becomes invalid at zero — Verification fails with code: USAGE_EXCEEDED
Keys without a credits configuration are unlimited and never hit usage limits.

Use cases

Subscription quotas

Pro plan: 50,000 requests/month. Credits reset automatically on the 1st.

Pay-per-use APIs

Sell 10,000 requests for $10. Key stops working when credits run out.

Trial tiers

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

One-time tokens

Generate a key that works exactly once, then expires.

Creating keys with usage limits

Basic credit limit

Verification response

When verifying a key with credits, the response includes the remaining balance:
The credits field shows remaining credits after this verification. If it returns 999, the key can be used 999 more times.
When credits are exhausted:

Custom costs per operation

Not all API operations are equal. Complex queries might cost 10 credits while simple lookups cost 1:
Verification fails if the key doesn’t have enough credits. A key with 5 remaining credits will reject a request with cost: 10.

Cost of zero

Set cost: 0 to verify a key without consuming credits. Useful for:
  • Health checks
  • Fetching key metadata
  • Checking validity before expensive operations

Dynamic pricing example

Adjust costs based on operation type:

Auto-refill for subscriptions

Auto-refill automatically restores credits on a schedule. Perfect for subscription models:

Monthly refill

Credits reset on the 1st of each month:

Custom refill day

If billing cycles start mid-month, use refillDay:
For months with fewer days (e.g., February with 28 days), refills happen on the last day of the month if refillDay exceeds the month’s length.

Daily refill

For free tiers with daily quotas:
Refill replaces the current balance — it doesn’t add to it. A key with 50 remaining credits will have exactly 1000 after a refill of 1000, not 1050.

Managing credits

Add credits manually

When users purchase additional credits:

Set exact credit amount

Deduct credits

Remove usage limits

Make a key unlimited:

Subscription tier patterns

Tiered plans

Upgrade flow

When a user upgrades mid-cycle:

Pay-as-you-go with top-ups

Combined with rate limits

Usage limits and rate limits solve different problems. Use both together:

Analytics and billing

Monitor credit consumption for billing insights:

Best practices

Analyze your API’s actual usage patterns before setting limits. Too restrictive and you’ll frustrate users; too generous and you’ll hurt profitability.
Send alerts when users reach 80% and 90% of their quota. Give them time to upgrade or purchase more credits.
Charge more for expensive operations. A 5-minute AI inference shouldn’t cost the same as a 10ms database lookup.
Usage limits alone won’t prevent abuse. A user could burn through 10,000 credits in 10 seconds without rate limiting.

Next steps

Rate limit overrides

Adjust rate limits dynamically per customer

Key expiration

Time-based limits for temporary access