npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

usagey

v0.1.3

Published

Official Node.js SDK for Usagey - Usage-Based Pricing Toolkit

Downloads

46

Readme

Usagey Node.js SDK

Test npm version codecov

The official Node.js SDK for Usagey - the complete toolkit for implementing usage-based pricing.

Installation

npm install usagey
# or
yarn add usagey

Quick Start

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

Features

  • Usage Tracking: Track usage events with custom metadata
  • API Key Management: Create, regenerate, and delete API keys
  • Usage Statistics: Retrieve usage statistics and limits
  • Type Safety: Written in TypeScript with full type definitions
  • Error Handling: Detailed error types for better error handling

API Reference

Initialization

import { UsageyClient } from 'usagey';

const usagey = new UsageyClient('your_api_key', {
  baseUrl: 'https://api.usagey.com'
});

Tracking Usage Events

// Basic usage
await usagey.trackEvent('api_call');

// With quantity
await usagey.trackEvent('data_processing', 5);

// With metadata
await usagey.trackEvent('storage', 10, {
  fileType: 'image',
  sizeInBytes: 1024000
});

Managing API Keys

// Create a new API key
const newKey = await usagey.createApiKey('Production API Key', 'org_123456');

// Create an API key with expiration
const expiringKey = await usagey.createApiKey(
  'Temporary API Key',
  'org_123456',
  new Date('2023-12-31')
);

// Regenerate an API key
const regeneratedKey = await usagey.regenerateApiKey('key_123456');

// Delete an API key
await usagey.deleteApiKey('key_123456');

Retrieving Usage Statistics

// Get current usage statistics
const stats = await usagey.getUsageStats();
console.log(`Current usage: ${stats.usage.currentUsage} / ${stats.usage.limit}`);
console.log(`Usage percentage: ${stats.usage.percentage}%`);
console.log(`Current plan: ${stats.usage.plan}`);

// Get usage events with filtering
const events = await usagey.getUsageEvents({
  eventType: 'api_call',
  startDate: '2023-01-01',
  endDate: new Date(),
  limit: 100
});

Error Handling

The SDK provides specific error classes for different types of errors:

import { UsageyClient, AuthenticationError, RateLimitError, ValidationError } from 'usagey';

const usagey = new UsageyClient('your_api_key');

try {
  await usagey.trackEvent('api_call');
} catch (error) {
  if (error instanceof AuthenticationError) {
    console.error('Invalid API key');
  } else if (error instanceof RateLimitError) {
    console.error(`Rate limit exceeded. Retry after ${error.retryAfter} seconds`);
  } else if (error instanceof ValidationError) {
    console.error('Validation error:', error.errors);
  } else {
    console.error('Unexpected error:', error);
  }
}

License

MIT