Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.onlyfanskit.dev/llms.txt

Use this file to discover all available pages before exploring further.

When you run the SDK in-process, connect to OnlyFans’ realtime stream directly with a short-lived auth token.
import { connectRealtime } from "onlyfanskit";

const { token } = await of.users.authToken();

const ws = await connectRealtime({
  authToken: token,
  onEvent: (evt) => {
    if (evt.api === "newMessage") {
      // handle new message
    }
  },
});
The token is a JWT valid for roughly 24 hours. Refresh it by calling users.authToken() again before it expires and reconnecting.

Event handling

onEvent receives each decoded event. Branch on evt.api for the event type (newMessage, and others). Keep the handler fast — offload heavy work to a queue so you don’t block the socket.

When to prefer SSE instead

If you’re calling the REST API rather than embedding the SDK, use Server-Sent Events — it gives you the same events without managing a WebSocket connection or token lifecycle.