The Plans module allows you to create and manage usage plans that define rate limits and features for your users.
List Plans
Get all plans for your account:
import { Limitly } from '@limitly/limitly-js';
const limitly = new Limitly({
apiKey: 'your_limitly_api_key'
});
// List all plans
const plans = await limitly.plans.list();
console.log('Plans:', plans.data);
Create Plan
Create a new usage plan:
const plan = await limitly.plans.create({
name: 'Basic Plan',
description: 'Plan for basic users',
max_requests: 10000,
request_period: 'month',
features: ['api_access', 'basic_analytics']
});
console.log('Created Plan:', plan.data);
Create Plan Parameters
A description of the plan
Maximum number of requests allowed per period
The period for the request limit (day, week, month, year)
Array of features included in this plan
Additional metadata for the plan
Get Plan
Retrieve a specific plan by ID:
const plan = await limitly.plans.get('plan_123');
console.log('Plan:', plan.data);
Update Plan
Update an existing plan:
const updatedPlan = await limitly.plans.update('plan_123', {
name: 'Updated Basic Plan',
max_requests: 15000,
features: ['api_access', 'basic_analytics', 'priority_support']
});
console.log('Updated Plan:', updatedPlan.data);
Update Plan Parameters
Updated description for the plan
Updated maximum number of requests
Updated array of features
Updated metadata for the plan
Delete Plan
Delete a plan (soft delete):
const result = await limitly.plans.delete('plan_123');
console.log('Delete result:', result.data?.message);
Get Plan Usage
Get usage statistics for a specific plan:
const usage = await limitly.plans.getUsage('plan_123');
console.log('Plan usage:', usage.data);
Plan Usage Response
Total number of users on this plan
Total requests made by users on this plan
Average usage per user on this plan
Get Plan Users
Get all users on a specific plan:
const users = await limitly.plans.getUsers('plan_123');
console.log('Plan users:', users.data);
Complete Example
import { Limitly } from '@limitly/limitly-js';
const limitly = new Limitly({
apiKey: 'your_limitly_api_key'
});
async function managePlans() {
// Create a basic plan
const basicPlan = await limitly.plans.create({
name: 'Basic Plan',
description: 'Perfect for small applications',
max_requests: 10000,
request_period: 'month',
features: ['api_access', 'basic_analytics']
});
console.log('Created Basic Plan:', basicPlan.data?.id);
// Create a pro plan
const proPlan = await limitly.plans.create({
name: 'Pro Plan',
description: 'For growing applications',
max_requests: 100000,
request_period: 'month',
features: ['api_access', 'advanced_analytics', 'priority_support', 'webhooks']
});
console.log('Created Pro Plan:', proPlan.data?.id);
// Get usage statistics
const usage = await limitly.plans.getUsage(basicPlan.data?.id!);
console.log('Basic plan usage:', usage.data);
// Get users on the plan
const users = await limitly.plans.getUsers(basicPlan.data?.id!);
console.log('Users on basic plan:', users.data);
// Update the plan
await limitly.plans.update(basicPlan.data?.id!, {
max_requests: 15000,
features: ['api_access', 'basic_analytics', 'email_support']
});
}
Plan Object
The plan object contains the following properties:
Unique identifier for the plan
The description of the plan
Maximum number of requests allowed per period
The period for the request limit
Array of features included in this plan
When the plan was created (ISO 8601 format)
When the plan was last updated (ISO 8601 format)
Additional metadata for the plan
Common Plan Features
Here are some common features you might include in your plans:
api_access
- Basic API access
basic_analytics
- Basic usage analytics
advanced_analytics
- Advanced analytics and reporting
priority_support
- Priority customer support
webhooks
- Webhook notifications
email_support
- Email support
phone_support
- Phone support
custom_domains
- Custom domain support
team_management
- Team and user management features
Next Steps