Skip to main content

Auto-Refill

Automatically restore usage credits for API keys on a daily or monthly schedule. Configure auto-refill amounts and intervals in Unkey.
2 min read

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#

Monthly subscription quotas

"Pro plan: 50,000 requests/month", credits reset on the 1st of each month.

Daily allowances

Free tier users get 100 requests per day, resets at midnight UTC.

Rolling credits

Automatically restore credits without manual intervention.

How it works#

  1. You create a key with credits.remaining and credits.refill configured
  2. Unkey automatically refills the credits on your chosen schedule
  3. Daily refills trigger at midnight UTC
  4. Monthly refills trigger on a specific day of the month (default: 1st)
Note

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.

Note

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#

ApproachBest for
Auto-refillSubscription models with predictable, recurring quotas
Manual incrementPay-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.

Next steps#