View the complete source code on GitHub.
Prerequisites
- Flowglad account with API key
- Next.js 15+ with App Router
- PostgreSQL database
Project Structure
Key Concepts
This pricing model combines subscription tiers with per-feature usage limits:- Toggle features - Binary access to capabilities (e.g., “GPT-5 Thinking”, “Agent Mode”)
- Usage credit grants - Monthly limits on specific features (e.g., 400 o3 messages/month)
- Unlimited vs. limited access - Features can be gated by toggle only, or by both toggle and usage limit
Implementation
Pricing Configuration
Thepricing.yaml defines features as toggles or usage credit grants. See the full configuration in the repository.
Checking Feature Access
UsecheckFeatureAccess to determine if a user has access to a feature. Use checkUsageBalance to get their remaining credits on a usage meter.
src/app/example.tsx
Gating UI Based on Access
Combine feature access and usage balance checks to determine button states.src/app/home-client.tsx
Recording Usage Events
When a user consumes a limited feature, record the usage event. The SDK’screateUsageEvent method on the useBilling() hook handles the server communication automatically.
src/app/home-client.tsx
subscriptionId from the customer’s current subscription. It defaults amount to 1 if not provided.
Helper Functions
The example includes helpers to work with usage meters and pricing data.src/lib/billing-helpers.ts