Usagey Documentation

Learn how to implement usage-based pricing with Usagey

Getting Started
Everything you need to know to get started 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.

Quick Start Steps:

  1. Create an account and set up your organization
  2. Create an API key for your application
  3. Implement usage tracking in your code
  4. Set up pricing plans and billing
  5. Monitor usage and revenue in the dashboard
Installation
How to install and set up Usagey in your application

Using the Node.js SDK (Recommended)

npm install usagey

Using Yarn

yarn add usagey

Direct API Integration

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.

Usage Tracking
How to track usage events in your application
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();
API Reference
Complete reference for the Usagey API

Endpoints

POST
/api/usage

Track a usage event

View Details
GET
/api/usage

Get usage events

View Details
GET
/api/usage/stats

Get usage statistics

View Details

Authentication

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
Node.js SDK
Use our official Node.js SDK for easier integration

Installation

npm install usagey

Basic Usage

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);
  }
}

SDK Features

  • Track usage events with custom metadata
  • Manage API keys (create, regenerate, delete)
  • Retrieve usage statistics and limits
  • Comprehensive error handling
  • TypeScript support with full type definitions