Auto-refill works with usage limits to automatically restore a key's credits on a schedule. Perfect for subscription models where users get a fresh allocation each billing period.
When to use this#
"Pro plan: 50,000 requests/month", credits reset on the 1st of each month.
Free tier users get 100 requests per day, resets at midnight UTC.
Automatically restore credits without manual intervention.
How it works#
- You create a key with
credits.remainingandcredits.refillconfigured - Unkey automatically refills the credits on your chosen schedule
- Daily refills trigger at midnight UTC
- Monthly refills trigger on a specific day of the month (default: 1st)
Refill replaces the current credit balance, it doesn't add to it. A key with 50 remaining credits will have exactly 1000 after a refill of 1000, not 1050.
Create a key with auto-refill#
Monthly refill (most common)#
Key gets 10,000 credits that reset on the 1st of each month:
Monthly refill on a specific day#
If your billing cycle is mid-month, set refillDay:
This refills on the 15th of each month.
For months with fewer days (e.g., February), refills on the last day of the
month if refillDay exceeds the month's length.
Daily refill#
Key gets 100 credits that reset every night at midnight UTC:
Update refill settings#
Change an existing key's refill configuration:
Disable refill#
To stop auto-refill but keep the current credits:
Common patterns#
Tiered subscription plans#
Upgrade a user's plan#
When a user upgrades, update their key:
Refill vs manual credit management#
| Approach | Best for |
|---|---|
| Auto-refill | Subscription models with predictable, recurring quotas |
| Manual increment | Pay-as-you-go, top-ups, credit purchases |
You can use both: set a base refill for the subscription, and manually increment when users purchase additional credits.