The Resource Data Model
Resources let you implement allocation-based pricing models. Here’s how the key components work together:-
Resources: Define the types of capacity you offer. Each resource has a slug (likeseatsorapi_keys) and belongs to a pricing model. Think of it as describing what can be allocated. -
Subscription Item Features: When a customer subscribes to a product, their subscription includes features that grant resource capacity. For example, a “Team Plan” might include 10 seats. This defines how much of each resource a customer can claim. -
Resource Claims: Individual allocations from a customer’s capacity pool. When a user joins a team and takes a seat, that’s a claim. Claims can be anonymous (just a count) or named (with an identifier like a user ID).
Resources are different from Usage: usage tracks consumption that gets billed (like tokens), while resources track allocations (like seats) that can be reserved and released.
Key Concepts
Capacity
Each subscription has a capacity limit for resources, determined by the product features. If a customer subscribes to a plan with “10 seats included,” their seat capacity is 10. Capacity can vary by pricing tier—a Pro plan might offer 25 seats while an Enterprise plan offers unlimited.Resource Claims
A claim represents an allocation from the capacity pool. When you claim a resource, you’re reserving it for use. Claims track:- When it was claimed (
claimedAt) - Who it’s for (
externalId, optional) - Custom data (
metadata, optional) - Release status (
releasedAt,releaseReason)
Named vs Anonymous Claims
Resources support two claiming modes: Named Claims use an identifier (externalId) to track exactly what each allocation is for:
- Idempotent—claiming the same ID twice returns the existing claim
- Easy to look up and release by identifier
- Ideal for tracking: “user_john has seat #3”
- No identifier attached
- Released in FIFO order (oldest first)
- Ideal for: “we need 3 more seats, don’t care which”
Common Use Cases
Setting Up Resources
Step 1: Create a Resource in Your Pricing Model
- Navigate to the Pricing Models page in your dashboard
- Select the pricing model you want to add the resource to
- Click “Create Resource”
- Provide a descriptive name (e.g., “Team Seats”) and slug (e.g.,
seats) - Save the resource
Step 2: Add Resource Capacity to a Product
When creating or editing a product’s features:- Add a new feature of type Resource
- Select the resource you created
- Set the capacity (e.g., 10 seats)
- Save the product
Working with Resources in Your App
Checking Available Capacity
Before allowing users to claim resources, check what’s available:lib/check-capacity.ts
Claiming Resources
Use named claims when you need to track what each allocation is for:lib/team-management.ts
lib/connection-pool.ts
Releasing Resources
Release named claims by their identifier:lib/team-management.ts
lib/connection-pool.ts
Listing Active Claims
View all active claims for a resource:lib/team-management.ts
API Response Shapes
Resource Usage
Resource Claim
Important Behaviors
Idempotent Named Claims
Claiming with the sameexternalId twice returns the existing claim without creating a duplicate. This makes the API safe for retries:
Capacity Enforcement
Claims fail if they would exceed capacity. Always check availability before attempting to claim, or handle the error gracefully:Capacity Aggregation
When a subscription has multiple items that provide capacity for the same resource (e.g., a base plan + add-on), the total capacity is aggregated across all subscription items. For example:- Pro Plan provides 10 seats
- Seat Add-On provides 5 additional seats
- Total capacity = 15 seats
getResourceUsages endpoint returns one entry per resource with the total aggregated capacity, not per subscription item.
Subscription Lifecycle
On Cancellation: When a subscription is canceled, all associated resource claims are automatically released with areleaseReason of "subscription_canceled". This ensures clean capacity management without manual cleanup.
Claims Persist Across Adjustments: Resource claims are scoped to the subscription and resource, not to individual subscription items. This means claims survive subscription adjustments—when you upgrade or downgrade plans, existing claims are preserved as long as they fit within the new capacity.
On Downgrade: When adjusting a subscription to a plan with lower capacity, Flowglad validates that existing claims fit within the new capacity. If the current claimed count exceeds the new capacity, the adjustment is blocked with an error message:
expiredAt timestamp set to the billing period end and automatically expire when the downgrade executes.
Auto-Resolution
If a customer has exactly one active subscription, thesubscriptionId parameter is optional—Flowglad automatically resolves it. For customers with multiple subscriptions, you must specify which one:
Full Example: Team Seat Management
Here’s a complete example showing how to implement team seat management:lib/team-seats.ts
Adjusting Subscriptions with Resources
When customers upgrade or downgrade plans, resource claims are preserved—but capacity validation ensures you can’t reduce capacity below active claims.Upgrade Flow: Adding More Seats
The most common upgrade is adding more seats to an existing plan. Use thequantity parameter to set the exact number of seats:
lib/add-seats.ts
lib/upgrade-plan.ts
Downgrade Flow
Downgrading requires releasing excess claims first. Flowglad validates capacity before allowing the change:lib/downgrade-with-seats.ts
Both immediate and scheduled downgrades are blocked if claimed resources exceed the new capacity. The
expiredAt mechanism only applies to new claims made during an interim period after a valid downgrade is scheduled—not to allowing downgrades when excess claims already exist.Building a Seat Adjustment UI
Here’s how to build a UI that handles seat-aware plan changes:lib/plan-change-handler.ts
Related
- Subscriptions - Resources are attached to subscription features
- Subscription Management - Adjusting subscriptions with
adjustSubscription - Usage - For consumption-based tracking instead of allocation
- Products - Define resource capacity in product features
- SDK Reference - Full SDK documentation for resources