Error Handling
Every error says what went wrong (code), which request it was (trace_id), and, when OnlyFans refused it, what OnlyFans answered (upstream_status). Use code for logic; quote trace_id when you ask for help.
Error Response Format
Every error body is a JSON object with error, code and trace_id. A 502 from OnlyFans adds what OnlyFans said.
{
"error": "Human-readable description of what went wrong.",
"code": "MACHINE_READABLE_CODE",
"trace_id": "9f3c2a71b0de"
}| Field | Present | Meaning |
|---|---|---|
error | Every error | Human-readable description. The text can change between releases: do not parse it. |
code | Most errors | Stable machine-readable code (table below). A few 400 and 404 answers about the request or the model carry only error. |
trace_id | Every error | The id of this request. Log it, and send it to support with the time and the endpoint. |
upstream_status | OF_API_ERROR only | The HTTP status OnlyFans itself answered with (401, 429, 500, ...). It is not the status you receive: that is always 502. |
upstream_message | OF_API_ERROR, when OnlyFans sent one | OnlyFans' own error text, when it sent a JSON one, cut to 300 characters. Never an HTML page. |
retry_after | OF_API_ERROR, when OnlyFans sent one | Seconds to wait, from OnlyFans' Retry-After header (1 to 3600). Also sent as the Retry-After header. |
Always switch on code, not error
error message text can change between releases. The code field is stable — use it in your switch/case logic.Response Headers
Two headers matter when something goes wrong. Both are sent in addition to the body fields above.
| Header | Sent | Meaning |
|---|---|---|
X-Trace-Id | Every response, success or error | The same id as trace_id in an error body. A success body is not changed: read the header. |
Retry-After | 502 OF_API_ERROR, when OnlyFans sent one | Whole seconds. v3's own 429 RATE_LIMIT_EXCEEDED does not send it: your plan's limit is per minute (sliding window). |
Using the Trace ID
The trace id ties your request to what happened on our side, so a problem can be found from one string.
- 1. Log
trace_id(or theX-Trace-Idheader) next to every request that fails. Keep it for successful requests too if you can: the header is always there. - 2. When you contact support, send the
trace_id, the endpoint, the model id and the time (with the time zone) of the request. - 3. With the id we find the request in our logs, including the call we made to OnlyFans for it and what OnlyFans answered.
An id is per request
HTTP Status Codes
Failed requests cost nothing
Common Error Examples
401 — Invalid API Key
HTTP 401 Unauthorized
{
"error": "The provided API key is invalid or has been revoked.",
"code": "INVALID_API_KEY",
"trace_id": "9f3c2a71b0de"
}402 — No Active Subscription
HTTP 402 Payment Required
{
"error": "Your organization does not have an active subscription.",
"code": "NO_SUBSCRIPTION",
"trace_id": "9f3c2a71b0de"
}402 — Insufficient Credits
HTTP 402 Payment Required
{
"error": "Not enough credits to complete this request.",
"code": "INSUFFICIENT_CREDITS",
"trace_id": "9f3c2a71b0de"
}400 — Invalid parameter
HTTP 400 Bad Request
{
"error": "'by' must be one of: total, new, renew",
"trace_id": "9f3c2a71b0de"
}400 — Model not connected
HTTP 400 Bad Request
{
"error": "Model is not connected",
"code": "MODEL_NOT_CONNECTED",
"trace_id": "9f3c2a71b0de"
}MODEL_NOT_CONNECTED
error and trace_id but no code; check the model id.404 — Model not found or not yours
HTTP 404 Not Found
{
"error": "Model not found or access denied",
"trace_id": "9f3c2a71b0de"
}429 — Rate Limit Exceeded (your plan)
HTTP 429 Too Many Requests
{
"error": "Rate limit exceeded. Slow down and try again.",
"code": "RATE_LIMIT_EXCEEDED",
"trace_id": "9f3c2a71b0de"
}502 — SIGN_ERROR
HTTP 502 Bad Gateway
{
"error": "Service temporarily unavailable. Please try again later.",
"code": "SIGN_ERROR",
"trace_id": "9f3c2a71b0de"
}504 — TIMEOUT
HTTP 504 Gateway Timeout
{
"error": "Request to OnlyFans timed out",
"code": "TIMEOUT",
"trace_id": "9f3c2a71b0de"
}500 — UNKNOWN_ERROR
HTTP 500 Internal Server Error
{
"error": "Model has no session data — reconnect required",
"code": "UNKNOWN_ERROR",
"trace_id": "9f3c2a71b0de"
}When OnlyFans Answers With an Error
OF_API_ERROR is always a 502, whatever OnlyFans said, so that OnlyFans' own 401 can never be mistaken for a problem with your API key. upstream_status is what OnlyFans said.
OnlyFans is rate limiting the model (upstream_status 429)
HTTP 502 Bad Gateway
X-Trace-Id: 9f3c2a71b0de
Retry-After: 12
{
"error": "OnlyFans returned 429",
"code": "OF_API_ERROR",
"upstream_status": 429,
"upstream_message": "Too many requests",
"retry_after": 12,
"trace_id": "9f3c2a71b0de"
}The model's session is dead (upstream_status 401)
HTTP 502 Bad Gateway
X-Trace-Id: 4be07c1d5a92
{
"error": "OnlyFans returned 401",
"code": "OF_API_ERROR",
"upstream_status": 401,
"trace_id": "4be07c1d5a92"
}| upstream_status | Usually means | What to do |
|---|---|---|
400 | OnlyFans rejected a parameter. Read upstream_message. | Fix the request. Retrying will not help. |
401 | OnlyFans no longer accepts this model's session (logged out, password changed, expired). It is not about your API key. | Reconnect the model in the dashboard (Models), then retry. |
403 | OnlyFans refuses this call for this account or resource. | Do not retry the same call. |
404 | OnlyFans has no such resource (a fan, chat or message that does not exist or is gone). | Check the id. Retrying will not help. |
429 | OnlyFans is slowing this model's session down. | Wait retry_after seconds if present, otherwise a few seconds, and ask for the same thing again. When paging, go slower. |
5xx | OnlyFans itself is failing. | Retry after a pause, with backoff. |
Two different 429s
429 with RATE_LIMIT_EXCEEDED is your plan's limit, counted by us. A 502 with upstream_status: 429is OnlyFans slowing down the model's session, for example while you page through a long list quickly. Both are worth a pause; only the second can carry retry_after.Error Code Reference
All machine-readable error codes you may encounter when using proxy endpoints, and whether asking again can help.
| Code | Status | Description | Retry? |
|---|---|---|---|
NO_API_KEY | 401 | The X-API-Key header is missing from the request. | No: add the header. |
INVALID_API_KEY | 401 | The API key is invalid or has been revoked. | No: use an active key. |
NO_SUBSCRIPTION | 402 | The organization does not have an active subscription. | No: subscribe to a plan. |
INSUFFICIENT_CREDITS | 402 | Credit balance is too low for this endpoint's cost. | No: top up or upgrade. |
INVALID_PARAM | 400 | A parameter has a value the endpoint cannot use. The error text says which. | No: fix the request. |
MISSING_QUERY | 400 | A required query parameter is missing. | No: fix the request. |
RATE_LIMIT_EXCEEDED | 429 | Too many requests for your plan in the last 60 seconds, per API key and per model. | Yes: after a pause, with backoff. |
OF_API_ERROR | 502 | OnlyFans answered with an error. upstream_status says which one; see the next section. | Depends on upstream_status. |
SIGN_ERROR | 502 | The request could not be signed, so it never reached OnlyFans. Usually temporary. If the text says 'session may be expired', the model's session has no login cookie: reconnect the model. | Yes after a few seconds, unless the text says the session is expired. |
OF_PROXY_UNREACHABLE | 502 | The tunnel to OnlyFans failed before anything was sent, twice. The request never reached OnlyFans. | Yes: it is safe to send again. |
TIMEOUT | 504 | OnlyFans did not answer in time. The request may have reached OnlyFans. | A read: yes, after a pause. A send: look for the message in /api/query first, a resend can deliver it twice. |
SSL_ERROR | 500 | A secure connection to OnlyFans could not be made. Usually temporary. | Yes: after a pause. |
UNKNOWN_ERROR | 500 | Another failure while talking to OnlyFans. If the text says 'reconnect required', the model has no usable session. | Read the text: reconnect the model, or retry once. |
Retrying
Retry only what a pause can fix, wait for the time you are told, and stop on an answer that will not change.
import time
import requests
def get_with_retry(url, params, key, tries=5):
for attempt in range(tries):
r = requests.get(url, params=params, headers={"X-API-Key": key})
if r.status_code < 400:
return r.json()["data"]
try:
err = r.json() # error, code, trace_id, upstream_*...
except ValueError:
err = {}
print("failed", r.status_code, err.get("code"), err.get("upstream_status"),
"trace_id", err.get("trace_id") or r.headers.get("X-Trace-Id"))
last = attempt == tries - 1
if r.status_code not in (429, 502, 504) or last:
r.raise_for_status() # your own error (400, 401, 402...) or out of tries
if err.get("code") == "OF_API_ERROR" and err.get("upstream_status") in (400, 401, 403, 404):
r.raise_for_status() # OnlyFans' answer to this request: asking again changes nothing
time.sleep(err.get("retry_after") or min(2 * 2 ** attempt, 30))async function getWithRetry(url, key, tries = 5) {
for (let attempt = 0; attempt < tries; attempt++) {
const res = await fetch(url, { headers: { "X-API-Key": key } })
if (res.ok) return (await res.json()).data
const err = await res.json().catch(() => ({})) // error, code, trace_id, upstream_*...
console.log("failed", res.status, err.code, err.upstream_status,
"trace_id", err.trace_id || res.headers.get("X-Trace-Id"))
const last = attempt === tries - 1
if (![429, 502, 504].includes(res.status) || last) throw new Error("HTTP " + res.status)
if (err.code === "OF_API_ERROR" && [400, 401, 403, 404].includes(err.upstream_status)) {
throw new Error("OnlyFans answered " + err.upstream_status) // asking again changes nothing
}
const waitSeconds = err.retry_after || Math.min(2 * 2 ** attempt, 30)
await new Promise((resolve) => setTimeout(resolve, waitSeconds * 1000))
}
}Paging a long list
stats/fans), ask for the same offset again after a 429 or 502, and slow the loop down if it happens often. See Reading a whole window in the API Reference.