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

chaturbapi

v2.0.0

Published

Library to interact with the Chaturbate API's

Readme

chaturbapi

TypeScript library to interact with the Chaturbate Affiliate API.
Provides a secure and typed way to query clicks, signups, earnings, and tokens.


Installation

npm install chaturbapi
# or
yarn add chaturbapi

Requires Node.js ≥ 18.17.


Basic usage

import { ChaturbAPI } from "chaturbapi";

const api = new ChaturbAPI("your_username", "your_token", {
  timeoutMs: 10_000,
  retries: 2,
});

const stats = await api.getStats({
  range: "last_7_days",
  breakdown: "day",
});

console.log(stats.rows);

Expected response (AffiliateStatsResponse)

{
  "range": "last_7_days",
  "breakdown": "day",
  "program": "affiliate",
  "columns": ["date", "clicks", "signups", "revenue"],
  "rows": [
    { "date": "2025-10-01", "clicks": 123, "signups": 12, "revenue": 45.5 },
    { "date": "2025-10-02", "clicks": 110, "signups": 9, "revenue": 33.7 }
  ],
  "totals": { "clicks": 233, "signups": 21, "revenue": 79.2 }
}

Client options

new ChaturbAPI(username, token, {
  baseURL: "https://chaturbate.com", // optional
  timeoutMs: 12000,                  // request timeout
  retries: 2,                        // automatic retries
  headers: { "User-Agent": "chaturbapi/1.0" }, // custom headers
  beforeRequest: (url) => console.log("➡️", url),
  afterResponse: (url, status) => console.log("⬅️", status)
});

Available methods

getStats(query?: AffiliateStatsQuery)

Retrieves affiliate statistics.

Parameters

| Name | Type | Description | |--------|------|-------------| | range | "today" \| "yesterday" \| "last_7_days" \| "last_30_days" \| "this_month" \| "last_month" \| "this_year" | Date range. | | breakdown | "none" \| "day" \| "month" \| "program" | Level of breakdown. | | program | "affiliate" \| "revshare" \| "ppv" \| "tokens" | Program type. |

Returns

Promise<AffiliateStatsResponse>


Real-time Events (EventsClient)

The EventsClient class provides a persistent connection to the Chaturbate Events API, allowing you to receive live notifications such as user entries, tips, chat messages, and more.

Basic usage

import { EventsClient } from "chaturbapi";

const events = new EventsClient("your_username", "your_events_token");

// Listen for specific events
events.on("broadcastStart", ({ broadcaster, user }) => {
  console.log(`📡 ${broadcaster} started streaming`);
});

events.on("tip", ({ user, tip }) => {
  console.log(`💰 ${user.username} sent ${tip.tokens} tokens`);
});

events.on("chatMessage", ({ user, message }) => {
  console.log(`💬 ${user.username}: ${message.message}`);
});

// Generic listener
events.on("event", (e) => console.log(`[Raw Event]`, e));

// Handle errors
events.on("error", (err) => console.error("Stream error:", err));

// Start listening
events.start();

Supported events

| Event | Description | Payload Type | |--------|--------------|---------------| | broadcastStart | Broadcaster started streaming | BroadcastEvent | | broadcastStop | Broadcast ended | BroadcastEvent | | userEnter | A user entered the room | BroadcastEvent | | userLeave | A user left the room | BroadcastEvent | | follow | User followed the broadcaster | BroadcastEvent | | unfollow | User unfollowed the broadcaster | BroadcastEvent | | fanclubJoin | User joined the fanclub | BroadcastEvent | | chatMessage | Public chat message | ChatMessageEvent | | privateMessage | Private message | PrivateMessageEvent | | tip | User sent a tip | TipEvent | | roomSubjectChange | Broadcaster updated room subject | RoomSubjectChangeEvent | | mediaPurchase | Media (photo/video) purchased | MediaPurchaseEvent |

Strongly typed payloads

Each event type has its own structure. Examples:

events.on("tip", ({ broadcaster, user, tip }) => {
  // user.username, tip.tokens, tip.isAnon, tip.message
});

events.on("chatMessage", ({ broadcaster, user, message }) => {
  // user.username, message.message, message.color
});

events.on("mediaPurchase", ({ broadcaster, user, media }) => {
  // media.name, media.tokens, media.type
});

These types are automatically inferred in TypeScript, so you get full IntelliSense support per event type.


Main types

AffiliateStatsResponse

interface AffiliateStatsResponse {
  range: string;
  breakdown: string;
  program?: string;
  columns: string[];
  rows: Record<string, any>[];
  totals?: Record<string, any>;
}

AffiliateStatsQuery

interface AffiliateStatsQuery {
  range?: string;
  breakdown?: string;
  program?: string;
}

Events

ChaturbAPI implements a simple typed EventEmitter.

api.on("statsUpdated", (data) => {
  console.log("Updated stats:", data);
});

api.on("error", (err) => {
  console.error("API error:", err);
});

| Event | Description | |--------|--------------| | statsUpdated | Triggered when a successful response is received. | | error | Triggered when a network or HTTP error occurs. |


Error handling

Network or API errors throw an HTTPError exception:

import { HTTPError } from "chaturbapi";

try {
  await api.getStats({ range: "today" });
} catch (err) {
  if (err instanceof HTTPError) {
    console.error("HTTP failure:", err.status, err.body);
  } else {
    console.error("Unexpected error:", err);
  }
}

Example use cases

1. Weekly summary

const stats = await api.getStats({ range: "last_7_days", breakdown: "day" });
console.table(stats.rows);

2. Log API errors

api.on("error", (e) => {
  // Send to your monitoring system
  console.error("[ALERT] Chaturbate API failure:", e);
});

3. Monthly dashboard totals

const { totals } = await api.getStats({ range: "this_month" });
console.log("Clicks:", totals?.clicks, "Revenue:", totals?.revenue);

4. Run multiple queries in parallel

const [today, month] = await Promise.all([
  api.getStats({ range: "today" }),
  api.getStats({ range: "this_month" }),
]);

Events summary

| Event | Main Properties | Notes | |-------------------|-------------------------------------|-------------------------------------------| | broadcastStart | broadcaster, user | Triggered when stream starts | | broadcastStop | broadcaster, user | Triggered when stream stops | | userEnter | broadcaster, user | User enters room | | userLeave | broadcaster, user | User leaves room | | follow | broadcaster, user | User followed broadcaster | | unfollow | broadcaster, user | User unfollowed broadcaster | | fanclubJoin | broadcaster, user | User joined fanclub | | chatMessage | broadcaster, user, message | Public chat message | | privateMessage | broadcaster, user, message | Private message (to broadcaster) | | tip | broadcaster, user, tip | User sent tokens | | roomSubjectChange | broadcaster, user, subject | Room subject updated | | mediaPurchase | broadcaster, user, media | Media (photo/video) purchased |

All events contain at least broadcaster and user fields.

Example: Using ChaturbAPI and EventsClient together

import { ChaturbAPI, EventsClient } from "chaturbapi";

const api = new ChaturbAPI("user", "token");
const events = new EventsClient("user", "event_token");

const stats = await api.getStats({ range: "today" });
console.log("Current clicks:", stats.totals?.clicks);

events.on("tip", ({ user, tip }) => {
  console.log(`${user.username} tipped ${tip.tokens} tokens`);
});

events.start();

License

MIT © Nikita Contreras