Learn how to implement usage-based pricing with Usagey
Usagey is a complete toolkit for implementing usage-based pricing in your applications. This guide will help you get started with tracking usage, setting up pricing plans, and billing your customers based on their consumption.
npm install usagey
yarn add usagey
If you prefer to integrate directly with our API without using the SDK, you can make HTTP requests to our endpoints. See the API Reference section for details.
import { UsageyClient } from 'usagey';
// Initialize the client with your API key
const usagey = new UsageyClient('YOUR_API_KEY', {
baseUrl: 'https://usagey.com' // Optional, defaults to https://api.usagey.com
});
// Track a usage event
async function trackApiCall() {
try {
const result = await usagey.trackEvent('api_call', 1, {
endpoint: '/users',
method: 'GET'
});
console.log('Event tracked:', result.event_id);
} catch (error) {
console.error('Error tracking event:', error);
}
}
trackApiCall();
All API requests require authentication using an API key. Include your API key in the Authorization header as a Bearer token.
Authorization: Bearer YOUR_API_KEY
npm install usagey
import { UsageyClient } from 'usagey';
// Initialize the client with your API key
const usagey = new UsageyClient('YOUR_API_KEY');
// Track a usage event
async function trackApiCall() {
try {
const result = await usagey.trackEvent('api_call', 1, {
endpoint: '/users',
method: 'GET'
});
console.log('Event tracked:', result.event_id);
} catch (error) {
console.error('Error tracking event:', error);
}
}