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.
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.
| Option | Type | Description |
|---|---|---|
apiKey | string | Your OFManager API key, from API Keys in platform.ofmanager.com. |
auth.onlyfansUserId | string | The 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:
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:
| Event | When it fires | Payload |
|---|---|---|
api2_chat_message | A 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 |
subscribed | Someone subscribes. | { user, timestamp } |
typing | Someone in a chat is typing. | { id } |
online | Users come online. | WsOnline[] |
chat_messages | The unread chat count changes. | number |
unread_tips | The unread tips count changes. | number |
chat_queue_update | A mass message is still sending. | WsChatQueueUpdate |
chat_queue_finish | A mass message finished sending. | WsChatQueueFinish |
chat_message_delete | A message is deleted. | string |
post_published | A 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:
| Option | Type | Default | Description |
|---|---|---|---|
reconnect | boolean | true | Enable automatic reconnection. |
reconnectInterval | number | 1000 | Initial reconnection delay in milliseconds. |
maxReconnectInterval | number | 30000 | Maximum reconnection delay (exponential backoff cap). |
maxReconnectAttempts | number | Infinity | Maximum number of reconnection attempts before giving up. Set to Infinity to retry forever. |
pingInterval | number | 25000 | How 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")