WebSockets
Subscribe to a model's real-time OnlyFans event feed through a persistent WebSocket connection. The gateway reads events off its own internal event stream and broadcasts them to every subscriber — it never opens a new OnlyFans session on your behalf.
Broadcast architecture
Endpoint
wss://api.onlyfans-api.ai/ws/bridge/{model_id}| Parameter | Type | Description |
|---|---|---|
model_id | path | UUID of the connected model to subscribe to |
X-API-Key | header | Your API key. Takes priority if both the header and the api_key query param are present. |
api_key | query | Fallback for clients that can't set custom headers (e.g. a browser WebSocket). |
Prefer the header
X-API-Key header from a server-side client (Node.js, Python, etc.) whenever possible. The api_key query param exists only for clients that can't set custom headers, such as a browser WebSocket — a query param can end up in server access logs, browser history, or proxy logs, so prefer the header when you have the choice.Connecting
Open the WebSocket connection. The gateway validates your API key, verifies the model is connected, then sends a confirmation message.
import WebSocket from "ws"
const ws = new WebSocket(
"wss://api.onlyfans-api.ai/ws/bridge/MODEL_UUID",
{ headers: { "X-API-Key": process.env.OF_API_KEY } }
)
ws.on("open", () => console.log("WS open"))
ws.on("message", (raw) => {
const msg = JSON.parse(raw.toString())
if (msg.connected) {
console.log("Subscribed to model:", msg.modelId)
return
}
if (msg.error) {
console.error("Error:", msg.error, msg.code)
return
}
// Real-time event: message, typing, block_user, chat_message_like, chat_message_unlike, chat_message_delete
console.log("Event:", msg)
})
ws.on("close", (code) => console.log("Closed:", code))
ws.on("error", (err) => console.error("WS error:", err))Confirmation message
// Sent by the gateway immediately after a successful subscription
{
"connected": true,
"modelId": "16f3d13b-9415-4e6b-babe-e8db6b31bd97"
}One socket for many models
GET /ws/bridge, with no model in the path: one connection follows several models, picked with messages you send. Same authentication, same event frames and same capacity rule as /ws/bridge/{model_id}, but a client following many models holds one connection instead of one per model.
wss://api.onlyfans-api.ai/ws/bridge- Authenticate as above: the
X-API-Keyheader, or theapi_keyquery param. Every model you follow must be connected to your API key's organization. Not billed per event, like the single-model socket. - Then subscribe. After
{"connected": true, "mode": "multi"}, send{"action": "subscribe", "model_ids": [...]}with the models' internal UUIDs, at most 500 ids of at most 64 characters per message. Each subscribe gets one answer listing the ids nowsubscribedand therefusedones with a code. Subscribing to a model you already follow is not an error: it is listed under subscribed again. Repeated ids in one message count once. - Refusal codes:
MODEL_NOT_FOUND(not connected to your organization),MODEL_NOT_CONNECTED(its session is not active), andMODEL_LIMIT(the socket already follows the maximum, 100 models by default). Refused ids do not close the socket. - Unsubscribe with
{"action": "unsubscribe", "model_ids": [...]}; the answer,released, lists the ids you were following. - Events are the frames of the Events section below, unchanged; use their
model_idto tell the models apart. - Every 60 seconds the gateway checks the models you follow. One that is no longer connected, or no longer linked to your organization, is dropped and announced with an
unsubscribedframe; the socket stays open for the others. - Nothing is kept for the socket. After a reconnect, subscribe again. A message that is not valid JSON of the shape above is answered with
BAD_REQUEST, andTEMPORARY_ERRORmeans the models could not be checked right now: send the subscribe again. Neither closes the socket.
Frames
// Server -> client, right after the handshake
{ "connected": true, "mode": "multi" }
// Client -> server
{ "action": "subscribe", "model_ids": ["16f3d13b-9415-4e6b-babe-e8db6b31bd97"] }
{ "action": "unsubscribe", "model_ids": ["16f3d13b-9415-4e6b-babe-e8db6b31bd97"] }
// Server -> client, one answer per subscribe
{ "subscribed": ["16f3d13b-9415-4e6b-babe-e8db6b31bd97"], "refused": [{ "model_id": "MODEL_UUID_2", "code": "MODEL_NOT_CONNECTED" }] }
// Server -> client, one answer per unsubscribe: the ids that were followed
{ "released": ["16f3d13b-9415-4e6b-babe-e8db6b31bd97"] }
// Server -> client, unprompted: a followed model stopped being connected (or linked to your organization)
{ "unsubscribed": { "model_id": "16f3d13b-9415-4e6b-babe-e8db6b31bd97", "code": "MODEL_NOT_CONNECTED" } }
// Server -> client: a message that is not the shape above (the socket stays open)
{ "error": "Expected {\"action\": \"subscribe\" | \"unsubscribe\", \"model_ids\": [...]} with at most 500 string ids", "code": "BAD_REQUEST" }Node.js
import WebSocket from "ws"
const ws = new WebSocket("wss://api.onlyfans-api.ai/ws/bridge", {
headers: { "X-API-Key": process.env.OF_API_KEY },
})
ws.on("message", (raw) => {
const msg = JSON.parse(raw.toString())
if (msg.connected) {
// {"connected": true, "mode": "multi"}: now pick the models
ws.send(JSON.stringify({
action: "subscribe",
model_ids: ["MODEL_UUID_1", "MODEL_UUID_2"],
}))
return
}
if (msg.subscribed) { console.log("Following:", msg.subscribed, "Refused:", msg.refused); return }
if (msg.released) { console.log("Released:", msg.released); return }
if (msg.unsubscribed) { console.log("Dropped:", msg.unsubscribed); return }
if (msg.error) { console.error("Error:", msg.error, msg.code); return }
// An event frame, the same as on /ws/bridge/{model_id}: msg.model_id says which model
console.log(msg.model_id, msg.event_type)
})Limits
Events
After subscribing, the gateway pushes one JSON message per event. This is a read-only feed — there is no way to send actions back through this connection.
| event_type | Description |
|---|---|
message | A chat message was saved: both fan-inbound and model-outgoing, distinguished by direction. The message is stored before the event is sent, so reading /api/query after it finds the message. A message the gateway recovers after a gap also arrives as message, so a live message and a recovered one look the same. |
message_status_changed | A stored message changed in a way you can see: is_opened, can_purchase or can_purchase_reason differs from the stored copy (for a PPV, the fan paid). Same fields as message, plus platform_message_id and changed, an object of {old, new} per field. |
ppv_purchase | A fan bought a PPV. Carries purchase_id, platform_chat_id, message_id (the OnlyFans message id, not the gateway's UUID), fan_platform_id, amount, amount_raw, sub_type and created_at; content is the raw OnlyFans frame. The stored message flips to paid shortly after, through message_status_changed. |
typing | A fan started typing in a conversation |
block_user | A fan was blocked |
chat_message_like | A fan liked one of the model's messages. content is the OnlyFans message id as a JSON string; it does not say which fan. A like the model gives (to a fan's message) is not announced. |
chat_message_unlike | A fan removed that like. Same content: the message id as a JSON string. Pinning, unpinning, bookmarking and un-bookmarking a message from the model's account are not announced either: no event exists for them (tested 2026-10-09). |
chat_message_delete | A chat message was unsent: on onlyfans.com, through DELETE /models/:model_id/messages/:message_id, or by the fan. content is the message's OnlyFans id as a JSON string. The gateway has already marked its stored copy as deleted when this event arrives. |
chat_queue_update | Progress of a queued send: a mass message, or a scheduled message. content is OnlyFans' queue object; its id is the queueId of the delivered messages, and for a mass message the id the mass-message call returned. A scheduled message sends one when it is created and more when it fires. |
chat_queue_finish | A queued send finished (isDone: true; check hasError and isCanceled). It names no recipient and carries no message: the message itself reaches the stored copy later, see below. |
chat_messages, messages | An account counter changed. chat_messages carries the unread chat count next to counters such as count_priority_chat and unread_tips; messages carries hasSystemNotifications. They have no wrapper: content is the whole frame. Reading or un-reading a single chat has no frame of its own. |
new_message | A message notification. content is the whole frame (new_message and hasSystemNotifications), not the message object; the stored message is announced by the message event. |
toasts, subscribed, post_*, and any other frame | The gateway relays every frame OnlyFans sends, so event_type can be a value not listed here. toasts, subscribed and post_updated have been seen; the other kinds (post_published, post_expire, post_fundraising_updated, stream_stop, newTagsCount, stories) are Not verified. Their shape is not documented. |
Every event carries entry_id, event_type, model_id, content and timestamp; the kinds above that add fields say so. For a frame relayed as OnlyFans sent it, event_type is the first key of the frame. contentis a JSON string of that key's value when the frame has one key, and of the whole frame when it has several (chat_messages, messages, new_message), so read its own keys instead of trusting event_typeto name everything in it. Typing events come from fans only; the model's own typing is never visible. OnlyFans re-sends a message when its media is ready; that re-send is not relayed, so read the message again for its media URL.
message event
// event_type: "message" — fired for both fan-inbound and model-outgoing messages
{
"entry_id": "1723190400000-0",
"event_type": "message",
"direction": "fan-inbound",
"model_id": "16f3d13b-9415-4e6b-babe-e8db6b31bd97",
"conversation_id": "8f2c1e...",
"message_id": "9a7b3d...",
"fan_platform_id": "12345678",
"timestamp": "2026-08-09T13:45:02.123Z",
"organizations": "[{\"organizationId\":\"...\",\"atlasOrganizationId\":null}]",
"content": "{...raw OnlyFans message frame...}"
}typing event
// event_type: "typing"
{
"entry_id": "1723190401500-0",
"event_type": "typing",
"model_id": "16f3d13b-9415-4e6b-babe-e8db6b31bd97",
"content": "{...raw OnlyFans typing frame...}",
"conversation_id": "8f2c1e...",
"timestamp": "2026-08-09T13:45:03.601Z"
}chat_message_delete event
// event_type: "chat_message_delete" — a message was unsent
{
"entry_id": "1759526712345-0",
"event_type": "chat_message_delete",
"model_id": "16f3d13b-9415-4e6b-babe-e8db6b31bd97",
"content": "\"11486645186108\"",
"timestamp": "2026-10-03T21:15:02.123456+00:00"
}contentis a JSON string, so parse it once to get the message's OnlyFans id, which is the platform_message_id of the stored message. The feed is live-only: if your connection drops you miss events, but the stored copy is still marked, so reload the thread when you reconnect.
chat_queue_update / chat_queue_finish event
// event_type: "chat_queue_update" or "chat_queue_finish" — progress of a mass or scheduled message
{
"entry_id": "1759526712400-0",
"event_type": "chat_queue_finish",
"model_id": "16f3d13b-9415-4e6b-babe-e8db6b31bd97",
"content": "{\"id\": 48210184194, \"date\": \"2026-10-07T18:55:00+00:00\", \"isReady\": true, \"isDone\": true, \"total\": 1, \"pending\": 0, \"canUnsend\": true, \"unsendSeconds\": 1000000, \"hasError\": false, \"isCanceled\": false, \"isCouplePeopleMedia\": false}",
"timestamp": "2026-10-03T21:03:21.481923+00:00"
}content is a JSON string. For a scheduled message date is the scheduled time, and the first chat_queue_update arrives when the message is created, with total: -1; the send itself runs when the time comes and ends with chat_queue_finish.
OnlyFans sends no message event for a queued send, a mass message and a scheduled message alike, so the message reaches the stored copy (and /api/query) only when the next message arrives in that chat, which can be hours later. The gateway cannot find the message sooner without reading the chat from OnlyFans, and reading a chat without a cursor marks it read. To show the send in the meantime, draw it from the API response, take its delivery from chat_queue_finish (match on id), and when the stored message arrives replace your own bubble by its queue_id. A message scheduled or sent on onlyfans.com has no bubble of yours and shows up late.
Delivery
At most once, no resume
entry_id to drop duplicates on your side. After you reconnect, read the state again through the REST API instead of assuming nothing was missed.- Backlog after idle (Not verified).The gateway keeps its read position between subscribers, so events that arrive while nobody is subscribed may reach the next subscriber late. Each model's feed is trimmed at roughly 50,000 entries. This is read from the code and has not been checked at runtime.
- No heartbeat from the gateway. It answers pings you send; ping every 20 to 30 seconds. The idle timeout of the proxy in front of the gateway is Not verified.
- Slow clients (Not verified). Events go to every subscriber of a model in turn, from one thread, with no buffer per connection, so a client that stops reading can hold up the others. Inferred from the code, not tested: consume events quickly and keep the handler light.
Connection Errors
Credentials are checked once, when you connect. If the connection cannot be established, the gateway sends one JSON error message and then closes the socket with a normal close (code 1000), not an HTTP 401 on the handshake. Because the close is clean, a client that reconnects only on a close other than 1000, as in the example below, does not loop on these errors. A key revoked later does not close an open connection. A model whose session dies later is noticed within about 60 seconds: /ws/bridge/{model_id} then sends the MODEL_NOT_CONNECTED error and closes, and the multi-model socket sends an unsubscribed frame for that model and stays open.
| Code | Meaning | Fix |
|---|---|---|
NO_CREDENTIAL | No X-API-Key header and no api_key query param | Add the X-API-Key header |
INVALID_API_KEY | API key is invalid or revoked | Generate a new key from the dashboard |
NO_SUBSCRIPTION | Organization has no active subscription | Subscribe to a plan in the Billing section |
MODEL_NOT_FOUND | Model UUID not found or not accessible | Verify the model UUID and org access |
MODEL_NOT_CONNECTED | Model session is not active | Reconnect the model from the Models page |
BRIDGE_CAPACITY | The server has no free WebSocket slot. The socket is closed with code 1013 (Try Again Later), not 1000 | Retry after a delay, with some randomness. On the multi-model socket one connection serves all your models |
Example error message
// Sent before the connection is closed
{
"error": "Model is not connected",
"code": "MODEL_NOT_CONNECTED"
}Reconnection
The gateway does not automatically reconnect on your behalf. If the socket closes unexpectedly, implement exponential backoff in your client before reopening the connection.
function connectWithRetry(modelId, apiKey, attempt = 0) {
const delay = Math.min(1000 * 2 ** attempt, 30000)
setTimeout(() => {
const ws = new WebSocket(
`wss://api.onlyfans-api.ai/ws/bridge/${modelId}`,
{ headers: { "X-API-Key": apiKey } }
)
ws.addEventListener("close", (e) => {
if (e.code !== 1000) { // not a clean close
connectWithRetry(modelId, apiKey, attempt + 1)
}
})
}, delay)
}