BetterFans Link SDK — OnlyFans APIBetterFans Link SDK
Core Capabilities

Realtime

Aggregate chat counts and notification events from the WebSocket EventBus.

The realtime plugins give you computed state from the EventBus — per-account chat counts and deduplicated notification events — without manually parsing raw WebSocket frames.

Realtime counts

Maintains an in-memory snapshot of chat and notification counts per account, updated live from WebSocket events.

import { OfApiClient } from "@betterfans/link-sdk"
import { realtimeCounts } from "@betterfans/link-sdk/plugins/realtime-counts"

const client = new OfApiClient({
  apiKey: process.env.BFL_API_KEY,
  plugins: [realtimeCounts()],
})

const counts = client.plugin.realtimeCounts

Reading counts

// Get counts for a specific account
const accountCounts = counts.getAccountCounts("123456789")

if (accountCounts) {
  console.log("Chat messages:", accountCounts.chat?.chatMessages)
  console.log("Priority chats:", accountCounts.chat?.countPriorityChat)
  console.log("Notifications:", accountCounts.notifications?.notificationCountBreakdown)
}

// Get the full snapshot across all accounts
const snapshot = counts.getSnapshot()
console.log("Initialized:", snapshot.initialized)

for (const [accountId, state] of snapshot.accounts) {
  console.log(accountId, state.chat?.chatMessages)
}

Subscribing to changes

React to count updates as they arrive:

const unsubscribe = counts.subscribe(() => {
  const snapshot = counts.getSnapshot()
  // re-render your UI, update a badge, etc.
})

// later
unsubscribe()

API

Prop

Type

Notification events

Surfaces engagement-critical events — tips, PPV purchases, new and returning subscribers — as a deduplicated stream with a 5-second dedup window.

import { OfApiClient } from "@betterfans/link-sdk"
import { notificationEvents } from "@betterfans/link-sdk/plugins/notification-events"

const client = new OfApiClient({
  apiKey: process.env.BFL_API_KEY,
  plugins: [notificationEvents()],
})

const notifications = client.plugin.notificationEvents

Event types

EventTriggered when
tipA tip is received
ppv_purchaseA pay-per-view message is purchased
new_subscriberA new user subscribes
returning_subscriberA previously expired subscriber resubscribes
fan_messageA fan sends a message

Subscribing to events

const unsubscribe = notifications.subscribe(() => {
  const { latestEvent, eventCount } = notifications.getSnapshot()

  if (latestEvent) {
    console.log(
      `[${latestEvent.type}]`,
      `Account: ${latestEvent.data.accountId}`,
      `Amount: ${latestEvent.data.amount}`,
    )
  }
})

Clearing

// Clear the latest event (e.g. after displaying a toast)
notifications.clearEvent()

API

Prop

Type

On this page