RAG & Search
Two complementary query APIs for your synced data. Use Semantic Search to find messages by meaning, or the Query DSL for precise structured queries across messages, chats, fans, and chunks.
Authentication
X-API-Key header. The key determines the organization scope — all results are automatically restricted to models belonging to your organization. You cannot query data outside your org regardless of filter values.Semantic Search
Find messages by meaning, not keyword. Queries are embedded using OpenAI's text-embedding-3-small model and matched against stored message chunk embeddings via vector similarity.
curl -X POST "https://api.onlyfans-api.ai/api/models/MODEL_UUID/rag/search" \
-H "X-API-Key: sk_live_your_key_here" \
-H "Content-Type: application/json" \
-d '{"query": "what does this fan like", "fan_id": "553393565", "top_k": 5}'| Parameter | Type | Description |
|---|---|---|
queryrequired | string | Natural language search query. The gateway embeds this and finds semantically similar messages. |
fan_id | string | OnlyFans fan platform ID. When provided, search is scoped to that fan's conversation only. |
top_k | integer | Number of top results to return.Default: 5 |
similarity_threshold | float | Minimum similarity score (0.0–1.0). Results below this score are excluded. 0.0 returns all results.Default: 0.0 |
before_context | integer | Number of messages to include before each anchor result.Default: 3 |
after_context | integer | Number of messages to include after each anchor result.Default: 3 |
include_raw_payload | boolean | When true, each anchor result includes the full raw OnlyFans message payload.Default: false |
{
"results": [
{
"anchor": {
"id": "9d5b817a-eced-46b6-831c-f68fbbaed798",
"chat_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"fan_platform_id": "553393565",
"chunk_type": "single",
"chunk_text": "I love outdoor hiking and photography",
"message_text": "I love outdoor hiking and photography",
"is_from_model": false,
"created_at": "2026-05-10T14:32:00+00:00",
"is_tip": false,
"price": 0
},
"context": [
{
"id": "8c3a506b-fba1-4d22-9e17-b2c1d7e89f01",
"message_text": "What are your hobbies?",
"is_from_model": true,
"created_at": "2026-05-10T14:31:30+00:00"
},
{
"id": "1e7f209c-dca2-4b33-af28-c3d2e8f90g12",
"message_text": "That's amazing! We should talk more about this.",
"is_from_model": true,
"created_at": "2026-05-10T14:32:45+00:00"
}
],
"distance": 0.1823,
"chunk_type": "single"
}
],
"query": "what does this fan like",
"model_id": "16f3d13b-9415-4e6b-babe-e8db6b31bd97",
"fan_platform_id": "553393565"
}| Field | Description |
|---|---|
results[].anchor | The matching message. All standard message fields plus chunk_text (the specific chunk that matched). |
results[].anchor.raw_payload | Full raw OnlyFans message payload. Only present when include_raw_payload: true. |
results[].context | Messages surrounding the anchor, ordered by created_at. Count controlled by before_context and after_context. |
results[].distance | Vector distance (0 = identical, 1 = completely different). Lower is more similar. |
results[].chunk_type | The type of embedding chunk that matched: single (full message) or metadata (structured fields). |
query | The original query string echoed back. |
model_id | Model UUID the search was scoped to. |
fan_platform_id | Fan platform ID if fan_id was provided, otherwise null. |
Similarity threshold
similarity_threshold to filter weak matches. A value of 0.7 is a good starting point — it corresponds to a distance of 0.3 or less. The formula is: similarity = 1 - distance.Query DSL
Structured queries across six whitelisted tables. All results are scoped to your organization — model_id values are validated against your org's connected models.
curl -X POST "https://api.onlyfans-api.ai/api/query" \
-H "X-API-Key: sk_live_your_key_here" \
-H "Content-Type: application/json" \
-d '{"table": "messages", "filters": {"fan_platform_id": {"eq": "553393565"}, "is_from_model": false}, "sort": {"field": "created_at", "direction": "desc"}, "limit": 5}'| Parameter | Type | Description |
|---|---|---|
tablerequired | string | Table to query. One of: messages, chats, fans, message_chunks, message_tags, of_daily_stats. |
filters | object | Filter conditions keyed by field name. Each value is an operator object e.g. {"gte": "2026-01-01"}. See filter operators below. |
fields | array | List of field aliases to return. Omit to return all default fields for the table. Opt-in fields (listed per table under Available Tables) are returned only when you name them here. |
sort.field | string | Field to sort by. Must be one of the table's sortable fields. of_daily_stats defaults to stat_date.Default: created_at |
sort.direction | string | Sort direction: asc or desc.Default: asc |
limit | integer | Number of rows to return. Maximum 1000.Default: 20 |
offset | integer | Pagination offset.Default: 0 |
include_raw_payload | boolean | messages table only. When true, each row includes the full raw OnlyFans payload.Default: false |
include_deleted | boolean | messages table only. Messages unsent on OnlyFans are hidden by default. When true, they are returned too, and each row includes its deleted_at (null for a message that was not unsent).Default: false |
{
"table": "messages",
"total": 1482,
"limit": 5,
"offset": 0,
"data": [
{
"message_id": "9d5b817a-eced-46b6-831c-f68fbbaed798",
"platform_message_id": "9130375619415",
"fan_platform_id": "553393565",
"model_id": "16f3d13b-9415-4e6b-babe-e8db6b31bd97",
"created_at": "2026-05-10T14:32:00+00:00",
"message_text": "I love outdoor hiking and photography",
"price": 0,
"is_tip": false,
"media_count": 0,
"is_from_model": false
}
]
}curl -X POST "https://api.onlyfans-api.ai/api/query" \
-H "X-API-Key: sk_live_your_key_here" \
-H "Content-Type: application/json" \
-d '{"table": "fans", "filters": {"total_spent": {"gte": 100}}, "sort": {"field": "total_spent", "direction": "desc"}, "limit": 3}'{
"table": "fans",
"total": 358,
"limit": 3,
"offset": 0,
"data": [
{
"fan_id": "c1d2e3f4-a5b6-7890-cdef-012345678901",
"fan_platform_id": "553393565",
"model_id": "16f3d13b-9415-4e6b-babe-e8db6b31bd97",
"display_name": "Harry",
"username": "sirharoldprince",
"total_spent": 2171.50,
"tips_spent": 1460.00,
"messages_spent": 597.50,
"subscribed_on": true,
"last_seen": "2026-06-18T09:14:00+00:00",
"can_receive_message": true,
"is_blocked": false,
"created_at": "2025-10-02T11:00:00+00:00",
"updated_at": "2026-06-18T09:14:00+00:00"
}
]
}curl -X POST "https://api.onlyfans-api.ai/api/query" \
-H "X-API-Key: sk_live_your_key_here" \
-H "Content-Type: application/json" \
-d '{"table": "of_daily_stats", "filters": {"model_id": "16f3d13b-9415-4e6b-babe-e8db6b31bd97", "stat_date": {"gte": "2026-10-01", "lte": "2026-10-03"}}}'{
"table": "of_daily_stats",
"total": 3,
"limit": 20,
"offset": 0,
"data": [
{
"model_id": "16f3d13b-9415-4e6b-babe-e8db6b31bd97",
"platform": "onlyfans",
"stat_date": "2026-10-01",
"gross_amount": "125.50",
"net_amount": "100.40",
"synced_at": "2026-10-01T05:00:11+00:00"
},
{
"model_id": "16f3d13b-9415-4e6b-babe-e8db6b31bd97",
"platform": "onlyfans",
"stat_date": "2026-10-02",
"gross_amount": "0.00",
"net_amount": "0.00",
"synced_at": "2026-10-02T05:00:09+00:00"
},
{
"model_id": "16f3d13b-9415-4e6b-babe-e8db6b31bd97",
"platform": "onlyfans",
"stat_date": "2026-10-03",
"gross_amount": "210.25",
"net_amount": "168.20",
"synced_at": "2026-10-03T05:00:12+00:00"
}
]
}Available Tables
Each table exposes a fixed set of filterable and returnable fields. You cannot query tables or fields not listed here.
Opt-in fields
fields to read them, e.g. "fields": ["platform_message_id", "reply_to_message"]. reply_to_message is the quoted message of a reply: an object with id, text, createdAt and fromUser, or null when the message is not a reply. The snapshot fields (is_pinned, is_liked, is_added_to_bookmarks, is_new, is_reported_by_me, is_canceled, is_media_ready) hold the value from when the message was first synced and are not updated afterwards: a pin, like or bookmark made later does not show up in them.of_daily_stats
gross_amount and net_amount summed across every earning category OnlyFans reports for that day. Only the daily total is stored, not the individual earnings. Amounts are decimal strings with two decimals ("432.14"), not numbers. stat_date is a UTC calendar day (YYYY-MM-DD), so a day can differ from the OnlyFans dashboard, which shows your local time. Filter it with gte, lte or eq. A day with no earnings is stored as 0.00; days before a model's first sync have no row. The daily sync runs at 05:00 UTC and rewrites the rows of today and of the two days before it, so today's row is a snapshot of the latest run (at most the first hours of the day), a day is complete once the 05:00 UTC run of the next day has written it, and it can still change slightly until the run after that. Older days are not rewritten. synced_at is when the row was last written.messagesSynced message records from fan conversations.| Filter fields | created_at, is_from_model, price, is_tip, media_count, message_text, fan_platform_id, model_id, is_from_queue, can_purchase_reason, changed_at, platform_message_id, queue_id (these two take eq and in, up to 500 values: look messages up by id, or find every message of one mass or welcome send by its queue id; queue_id is returned when named in fields) |
| Sort fields | created_at, price, media_count |
| Return fields | message_id, platform_message_id, fan_platform_id, model_id, created_at, message_text, price, is_tip, media_count, is_from_model, giphy_id, is_from_queue, can_purchase_reason, changed_at |
| Opt-in fields | raw_payload (via include_raw_payload: true), deleted_at (via include_deleted: true). Named in fields: chat_id, sender_platform_id, synced_at, locked_text, is_free, from_user, to_user, previews, release_forms, reply_to_message, queue_id, response_type, chat_user_id, cancel_seconds, can_unsend_queue, unsend_seconds_queue, tip_text, tip_amount, is_fund_raising_tip, is_couple_people_media, is_markdown_disabled, can_report, can_be_pinned, is_opened, can_purchase. Snapshot, not live (see the note above): is_pinned, is_liked, is_added_to_bookmarks, is_new, is_reported_by_me, is_canceled, is_media_ready |
chatsChat thread records — one per fan–model pair.| Filter fields | created_at, updated_at, fan_platform_id, model_id |
| Sort fields | created_at, updated_at |
| Return fields | chat_id, platform_chat_id, fan_platform_id, model_id, created_at, updated_at |
| Opt-in fields | Named in fields: message_count, last_message_at, last_message_preview, last_message_from_model |
fansEnriched fan profiles with spending and subscription data.| Filter fields | fan_platform_id, model_id, is_verified, subscribed_on, subscribed_by, can_receive_message, is_blocked, is_restricted, tips_enabled, last_seen, created_at, updated_at, total_spent, messages_spent, tips_spent, subscribe_price, tips_min, tips_max |
| Sort fields | total_spent, messages_spent, tips_spent, subscribe_price, last_seen, created_at, updated_at |
| Return fields | fan_id, fan_platform_id, model_id, display_name, username, name, avatar, avatar_thumbs, is_verified, subscribed_on, subscribed_on_duration, subscribed_by, last_seen, can_receive_message, is_blocked, is_restricted, tips_enabled, tips_min, tips_max, subscribe_price, total_spent, messages_spent, tips_spent, posts_spent, subscriptions_spent, created_at, updated_at |
| Opt-in fields | Named in fields: spending_updated_at |
message_chunksVector embedding chunks derived from messages. Used for semantic search.| Filter fields | message_id, chunk_type, created_at, model_id, fan_platform_id |
| Sort fields | created_at |
| Return fields | chunk_id, message_id, chunk_type, text, normalized_text, embedding, chunk_metadata, created_at |
| Opt-in fields | Named in fields: chat_id, model_id, fan_platform_id |
message_tagsYour own key/value tags on a sent message (see the tags field on Send Message). Filter on tags.<your key> — the key is whatever you named it, not a fixed field.| Filter fields | model_id, fan_platform_id, tags.<key> (e.g. tags.xpromo_key) |
| Sort fields | created_at |
| Return fields | platform_message_id, model_id, fan_platform_id, tags, created_at |
| Opt-in fields | — |
of_daily_statsStored daily earnings from OnlyFans — one row per model per day. See the note below the table list.| Filter fields | model_id, stat_date |
| Sort fields | stat_date (default) |
| Return fields | model_id, platform, stat_date, gross_amount, net_amount, synced_at |
| Opt-in fields | — |
Filter Operators
Filters are expressed as an object keyed by field name. Each value is either a direct value (shorthand for eq) or an operator object.
{
"filters": {
"fan_platform_id": "553393565", // shorthand eq
"created_at": {
"gte": "2026-01-01T00:00:00Z",
"lte": "2026-06-30T23:59:59Z"
},
"total_spent": { "gte": 50 },
"is_from_model": { "eq": false },
"message_text": { "like": "%birthday%" },
"fan_platform_id": { "in": ["553393565", "123220869", "37098033"] }
}
}Filtering message_tags
tags.<key> is a special case: the key after the dot is whatever you named it when you sent the message (see tags on Send Message), not a fixed field — so it can't be listed in the table above. Only eq is supported.{
"table": "message_tags",
"filters": {
"tags.xpromo_key": "summer2026_to_modelB",
"fan_platform_id": "553393565"
}
}| Operator | Supported types | Description |
|---|---|---|
eq | string, integer, float, bool, datetime | Exact match. Shorthand: pass a value directly without wrapping in an object. |
gte | integer, float, datetime | Greater than or equal to. |
lte | integer, float, datetime | Less than or equal to. |
gt | integer, float, datetime | Strictly greater than. |
lt | integer, float, datetime | Strictly less than. |
in | string | Match any value in a list. Maximum 500 values. |
like | string | Case-insensitive substring match. Use % as wildcard: %keyword%. |
DSL Error Codes
All DSL validation errors return HTTP 400 with a code field identifying the rejection reason.
{
"error": "Filter field 'unknown_field' not allowed for table 'messages'",
"code": "DSL_ERROR"
}| Code | Status | Description |
|---|---|---|
MISSING_TABLE | 400 | The table field was not provided in the request body. |
INVALID_TABLE | 400 | The requested table is not in the allowed list. |
INVALID_FILTERS | 400 | The filters field is not a valid object. |
INVALID_FIELDS | 400 | The fields field is not a valid array. |
INVALID_PAGINATION | 400 | limit or offset is not an integer. |
DSL_ERROR | 400 | A filter field, operator, or return field is not allowed. The error message specifies which field caused the rejection. |
Org scoping is always enforced
model_id filter that belongs to another organization, the query will return zero rows — not an error. All results are silently restricted to models in your org before any user-provided filters are applied.Pagination
The DSL query endpoint uses offset-based pagination.
| Field | Description |
|---|---|
total | Total number of rows matching the filters (before limit/offset). Use this to calculate page count. |
limit | The limit applied to this request (echoed back). |
offset | The offset applied to this request (echoed back). |
data | Array of result rows for this page. |
// Page through all results
let offset = 0
const limit = 100
let allData = []
do {
const res = await fetch(`${BASE_URL}/api/query`, {
method: "POST",
headers: { "X-API-Key": apiKey, "Content-Type": "application/json" },
body: JSON.stringify({ table: "messages", filters: {}, limit, offset }),
})
const { data, total } = await res.json()
allData.push(...data)
offset += limit
} while (offset < total)Maximum limit is 1,000