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
| Use Case | Resource Slug | Claim Mode |
|---|---|---|
| Team seats | seats | Named (track which users) |
| API keys | api_keys | Named (track each key) |
| Project limits | projects | Named (track each project) |
| Concurrent connections | connections | Anonymous (just count) |
| Workspace limits | workspaces | Named (track each workspace) |
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:Subscription Lifecycle
When a subscription is canceled, all associated resource claims are automatically released. This ensures clean capacity management without manual cleanup. When downgrading to a plan with lower capacity, Flowglad prevents the change if the current claimed count exceeds the new capacity. The customer must first release enough resources before downgrading.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
Related
- Subscriptions - Resources are attached to subscription features
- Usage - For consumption-based tracking instead of allocation
- Products - Define resource capacity in product features
- SDK Reference - Full SDK documentation