API docs / Live Events

Live Events

Live events

Get live OnlyFans events for each creator over a WebSocket: new messages, typing, new subscribers, fans coming online and unread counts, with your API key.

Each creator's OnlyFans account sends live events the moment they happen: new chat messages, typing, new subscribers, fans coming online, unread counts and mass message progress. OfWsClient opens a WebSocket for one creator and hands you every event, fully typed.

live.ts
import { OfWsClient } from "@betterfans/link-sdk"

const ws = new OfWsClient({
  apiKey: process.env.OFM_API_KEY,
  auth: { onlyfansUserId: "123456789" }, // the creator to listen to
})

ws.on("api2_chat_message", (msg) => {
  console.log(`${msg.fromUser?.name ?? "Someone"}: ${msg.text}`)
})

ws.on("subscribed", (event) => {
  console.log(`New subscriber: ${event.user.name}`)
})

ws.connect()

Authentication

A connection needs the same two things as an HTTP request: your API key and the creator's OnlyFans user ID. Nothing else.

OptionTypeDescription
apiKeystringYour OFManager API key, from API Keys in platform.ofmanager.com.
auth.onlyfansUserIdstringThe creator to listen to. Their user ID is listed under Linked OnlyFans accounts on the API Keys page.

The key has to be allowed to act as that creator. An organization-wide key works for every creator in your agency. A key limited to specific creators works only for those.

Listen to every creator

Each connection covers one creator, so open one per creator:

all-creators.ts
import { OfWsClient } from "@betterfans/link-sdk"

// Your creators' OnlyFans user IDs, from the API Keys page
const creators = ["111111111", "222222222"]

for (const creatorId of creators) {
  const ws = new OfWsClient({
    apiKey: process.env.OFM_API_KEY,
    auth: { onlyfansUserId: creatorId },
  })

  ws.on("api2_chat_message", (msg) => {
    console.log(`[${creatorId}] ${msg.fromUser?.name ?? "Someone"}: ${msg.text}`)
  })

  ws.connect()
}

Events

Register a handler with .on(event, handler). The payload is typed for each event. These are the ones most integrations use:

EventWhen it firesPayload
api2_chat_messageA chat message arrives. A tip sent in chat arrives here too, with isTip and tipAmount.WsChatMessage with id, text, fromUser, price, media, isTip, tipAmount, createdAt
subscribedSomeone subscribes.{ user, timestamp }
typingSomeone in a chat is typing.{ id }
onlineUsers come online.WsOnline[]
chat_messagesThe unread chat count changes.number
unread_tipsThe unread tips count changes.number
chat_queue_updateA mass message is still sending.WsChatQueueUpdate
chat_queue_finishA mass message finished sending.WsChatQueueFinish
chat_message_deleteA message is deleted.string
post_publishedA post goes live.WsPostPublished

The event reference lists every event. To see everything that arrives while you build, log it all:

ws.onAny((event, payload) => {
  console.log(event, payload)
})

Connection lifecycle

// Connect
ws.connect()

// Check state
console.log(ws.state)     // "connecting" | "connected" | "reconnecting" | "disconnected"
console.log(ws.connected) // boolean

// Disconnect
ws.disconnect()

Reconnection

The client reconnects automatically when the connection drops. Configure the reconnection behavior:

OptionTypeDefaultDescription
reconnectbooleantrueEnable automatic reconnection.
reconnectIntervalnumber1000Initial reconnection delay in milliseconds.
maxReconnectIntervalnumber30000Maximum reconnection delay (exponential backoff cap).
maxReconnectAttemptsnumberInfinityMaximum number of reconnection attempts before giving up. Set to Infinity to retry forever.
pingIntervalnumber25000How often, in milliseconds, the client sends a keepalive ping.

State changes

Watch the connection state, and catch errors thrown inside your handlers:

const ws = new OfWsClient({
  apiKey: process.env.OFM_API_KEY,
  auth: { onlyfansUserId: "123456789" },
  onStateChange: (state) => {
    console.log(`Connection state: ${state}`)
    // "connecting" | "connected" | "reconnecting" | "disconnected"
  },
  onError: (event, payload, error) => {
    console.error(`Handler error for "${event}":`, error)
  },
})

Removing handlers

// Remove the handler for one event
ws.off("api2_chat_message")