Usage Limits
Enforce per-user image upload quotas to prevent abuse and manage resource allocation. Pixflare includes three built-in plan tiers with different limits.
Why It's Needed
Without usage limits, a single user could upload unlimited images and exhaust storage. Plan-based quotas let you offer tiered access (free, starter, pro) and prevent runaway storage costs.
This is separate from rate limiting. Rate limits prevent abuse in short time windows (10 uploads per minute). Usage limits enforce long-term quotas (100 images total on free plan).
Setup
Enable usage limits with:
USAGE_LIMITS_ENABLED='true'When disabled (default), users can upload unlimited images.
Default Plan Tiers
Pixflare includes three hardcoded plan tiers:
- Free: 100 images max
- Starter: 1,000 images max
- Pro: 25,000 images max
Users are assigned a plan tier in the database (users.plan_tier column). New users default to free unless you modify the signup logic.
Customizing Limits
To change plan limits, edit packages/config/src/usage-limits.ts:
PLANS: {
free: {
MAX_IMAGES: 100, // Change this
label: 'Free',
},
starter: {
MAX_IMAGES: 1000,
label: 'Starter',
},
pro: {
MAX_IMAGES: 25000,
label: 'Pro',
},
}After editing, rebuild and deploy:
pnpm --filter @pixflare/config build && pnpm --filter @pixflare/api build && pnpm deploy:prodHow it Works
When a user uploads an image, Pixflare checks their current image count against their plan limit. If they're at or over the limit (with 1% grace margin), the upload is rejected with a 403 error.
Usage counts are cached in KV for 5 minutes to avoid hammering the database on every upload. The cache invalidates when users delete images.
Grace percentage: Users can upload 1% over their limit to prevent frustrating edge cases where the count fluctuates due to concurrent deletes/uploads. So free tier users effectively get 101 images before hard rejection.
No bandwidth limits: Pixflare only limits image count, not storage size or bandwidth. All plans can upload any file size (up to 100MB single file limit) and serve unlimited bandwidth.