The API Keys module allows you to create, manage, and track API keys for your users.
List API Keys
Get all API keys for your account:
import { Limitly } from '@limitly/limitly-js';
const limitly = new Limitly({
apiKey: 'your_limitly_api_key'
});
// List all API keys
const keys = await limitly.apiKeys.list();
console.log('API Keys:', keys.data);
Create API Key
Create a new API key for a user:
const newKey = await limitly.apiKeys.create({
name: 'New API Key',
user_id: 'user_123',
plan_id: 'plan_456'
});
console.log('New API Key:', newKey.data?.api_key);
Create API Key Parameters
A descriptive name for the API key
The ID of the user who will use this API key
The ID of the plan to associate with this API key
Additional metadata for the API key
Get API Key
Retrieve a specific API key by ID:
const key = await limitly.apiKeys.get('key_123');
console.log('API Key:', key.data);
Update API Key
Update an existing API key:
const updatedKey = await limitly.apiKeys.update('key_123', {
name: 'Updated API Key Name',
metadata: {
environment: 'production'
}
});
console.log('Updated API Key:', updatedKey.data);
Update API Key Parameters
Updated metadata for the API key
Delete API Key
Delete an API key (soft delete):
const result = await limitly.apiKeys.delete('key_123');
console.log('Delete result:', result.data?.message);
Regenerate API Key
Regenerate an existing API key (creates a new key value):
const regeneratedKey = await limitly.apiKeys.regenerate('key_123');
console.log('New API Key:', regeneratedKey.data?.api_key);
Get API Key Usage
Get usage statistics for a specific API key:
const usage = await limitly.apiKeys.getUsage('key_123');
console.log('Usage:', usage.data);
Usage Response
Current usage count for the period
The limit for the current period
Remaining requests for the period
When the usage will reset (ISO 8601 format)
The current period (day, week, month)
Get API Key Requests
Get detailed request history for an API key:
const requests = await limitly.apiKeys.getRequests('key_123');
console.log('Request history:', requests.data);
Request History Response
When the request was made (ISO 8601 format)
The endpoint that was called
The validation status (allowed/denied)
The IP address of the request
Complete Example
import { Limitly } from '@limitly/limitly-js';
const limitly = new Limitly({
apiKey: 'your_limitly_api_key'
});
async function manageApiKeys() {
// Create a new API key
const newKey = await limitly.apiKeys.create({
name: 'Production API Key',
user_id: 'user_123',
plan_id: 'plan_456'
});
console.log('Created API Key:', newKey.data?.api_key);
// Get usage statistics
const usage = await limitly.apiKeys.getUsage(newKey.data?.id!);
console.log('Current usage:', usage.data?.current_usage);
console.log('Limit:', usage.data?.limit);
console.log('Remaining:', usage.data?.remaining);
// Get request history
const requests = await limitly.apiKeys.getRequests(newKey.data?.id!);
console.log('Recent requests:', requests.data?.requests);
// Update the API key
await limitly.apiKeys.update(newKey.data?.id!, {
name: 'Updated Production API Key',
metadata: {
environment: 'production',
team: 'backend'
}
});
}
API Key Object
The API key object contains the following properties:
Unique identifier for the API key
The actual API key value (only shown on creation/regeneration)
The ID of the user who owns this API key
The ID of the plan associated with this API key
When the API key was created (ISO 8601 format)
When the API key was last updated (ISO 8601 format)
Additional metadata for the API key
Next Steps