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.

JSON
{
  "error":    "Human-readable description of what went wrong.",
  "code":     "MACHINE_READABLE_CODE",
  "trace_id": "9f3c2a71b0de"
}
FieldPresentMeaning
errorEvery errorHuman-readable description. The text can change between releases: do not parse it.
codeMost errorsStable machine-readable code (table below). A few 400 and 404 answers about the request or the model carry only error.
trace_idEvery errorThe id of this request. Log it, and send it to support with the time and the endpoint.
upstream_statusOF_API_ERROR onlyThe HTTP status OnlyFans itself answered with (401, 429, 500, ...). It is not the status you receive: that is always 502.
upstream_messageOF_API_ERROR, when OnlyFans sent oneOnlyFans' own error text, when it sent a JSON one, cut to 300 characters. Never an HTML page.
retry_afterOF_API_ERROR, when OnlyFans sent oneSeconds to wait, from OnlyFans' Retry-After header (1 to 3600). Also sent as the Retry-After header.

Always switch on code, not error

The 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.

HeaderSentMeaning
X-Trace-IdEvery response, success or errorThe same id as trace_id in an error body. A success body is not changed: read the header.
Retry-After502 OF_API_ERROR, when OnlyFans sent oneWhole 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. 1. Log trace_id (or the X-Trace-Id header) next to every request that fails. Keep it for successful requests too if you can: the header is always there.
  2. 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. 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

Every request gets a new id, including each retry. Log the id of every attempt, not only the last one.

HTTP Status Codes

200OKRequest succeeded — credits deducted
400Bad RequestInvalid parameter or body, or the model is not connected
401UnauthorizedMissing or invalid API key
402Payment RequiredNo active subscription, or insufficient credits
404Not FoundThe model does not exist or is not yours
429Too Many RequestsYour plan's rate limit was exceeded — slow down
500Internal Server ErrorA failure on our side or while connecting to OnlyFans (UNKNOWN_ERROR, SSL_ERROR)
502Bad GatewayOnlyFans answered with an error (OF_API_ERROR), or the request could not be signed or sent (SIGN_ERROR, OF_PROXY_UNREACHABLE)
504Gateway TimeoutOnlyFans did not answer in time (TIMEOUT)

Failed requests cost nothing

Credits are deducted only on a 200. Every error above is free, and so is a retry that fails.

Common Error Examples

401 — Invalid API Key

JSON
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

JSON
HTTP 402 Payment Required

{
  "error": "Your organization does not have an active subscription.",
  "code": "NO_SUBSCRIPTION",
  "trace_id": "9f3c2a71b0de"
}

402 — Insufficient Credits

JSON
HTTP 402 Payment Required

{
  "error": "Not enough credits to complete this request.",
  "code": "INSUFFICIENT_CREDITS",
  "trace_id": "9f3c2a71b0de"
}

400 — Invalid parameter

JSON
HTTP 400 Bad Request

{
  "error": "'by' must be one of: total, new, renew",
  "trace_id": "9f3c2a71b0de"
}

400 — Model not connected

JSON
HTTP 400 Bad Request

{
  "error": "Model is not connected",
  "code": "MODEL_NOT_CONNECTED",
  "trace_id": "9f3c2a71b0de"
}

MODEL_NOT_CONNECTED

The model's OnlyFans session is not active. That includes a session OnlyFans has stopped recognising: the gateway marks the model disconnected, and every call for it returns this 400 until you reconnect it in the dashboard. Do not retry it. The 404 answer about the model id carries error and trace_id but no code; check the model id.

404 — Model not found or not yours

JSON
HTTP 404 Not Found

{
  "error": "Model not found or access denied",
  "trace_id": "9f3c2a71b0de"
}

429 — Rate Limit Exceeded (your plan)

JSON
HTTP 429 Too Many Requests

{
  "error": "Rate limit exceeded. Slow down and try again.",
  "code": "RATE_LIMIT_EXCEEDED",
  "trace_id": "9f3c2a71b0de"
}

502 — SIGN_ERROR

JSON
HTTP 502 Bad Gateway

{
  "error": "Service temporarily unavailable. Please try again later.",
  "code": "SIGN_ERROR",
  "trace_id": "9f3c2a71b0de"
}

504 — TIMEOUT

JSON
HTTP 504 Gateway Timeout

{
  "error": "Request to OnlyFans timed out",
  "code": "TIMEOUT",
  "trace_id": "9f3c2a71b0de"
}

500 — UNKNOWN_ERROR

JSON
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)

JSON
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)

JSON
HTTP 502 Bad Gateway
X-Trace-Id: 4be07c1d5a92

{
  "error": "OnlyFans returned 401",
  "code": "OF_API_ERROR",
  "upstream_status": 401,
  "trace_id": "4be07c1d5a92"
}
upstream_statusUsually meansWhat to do
400OnlyFans rejected a parameter. Read upstream_message.Fix the request. Retrying will not help.
401OnlyFans 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.
403OnlyFans refuses this call for this account or resource.Do not retry the same call.
404OnlyFans has no such resource (a fan, chat or message that does not exist or is gone).Check the id. Retrying will not help.
429OnlyFans 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.
5xxOnlyFans itself is failing.Retry after a pause, with backoff.

Two different 429s

A 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.

CodeStatusDescriptionRetry?
NO_API_KEY401The X-API-Key header is missing from the request.No: add the header.
INVALID_API_KEY401The API key is invalid or has been revoked.No: use an active key.
NO_SUBSCRIPTION402The organization does not have an active subscription.No: subscribe to a plan.
INSUFFICIENT_CREDITS402Credit balance is too low for this endpoint's cost.No: top up or upgrade.
INVALID_PARAM400A parameter has a value the endpoint cannot use. The error text says which.No: fix the request.
MISSING_QUERY400A required query parameter is missing.No: fix the request.
RATE_LIMIT_EXCEEDED429Too many requests for your plan in the last 60 seconds, per API key and per model.Yes: after a pause, with backoff.
OF_API_ERROR502OnlyFans answered with an error. upstream_status says which one; see the next section.Depends on upstream_status.
SIGN_ERROR502The 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_UNREACHABLE502The tunnel to OnlyFans failed before anything was sent, twice. The request never reached OnlyFans.Yes: it is safe to send again.
TIMEOUT504OnlyFans 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_ERROR500A secure connection to OnlyFans could not be made. Usually temporary.Yes: after a pause.
UNKNOWN_ERROR500Another 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.

Retry with the error fields (Python)
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))
Retry with the error fields (JavaScript)
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

When you page through a long list (for example 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.

Best Practices

Switch on code, not error messageThe error field is human-readable and can change. The code field is stable — always use it in your logic.
Log the trace_id of every failureWith it we can find the request, our call to OnlyFans and OnlyFans' answer. Without it we can only guess from the time.
Read upstream_status on a 502401 means the model's session is dead (reconnect it); 429 means slow down; 5xx means OnlyFans is failing. Only 429, 5xx and the signing and tunnel errors are worth retrying.
Retry only on 429, 500, 502 and 504400, 401, 402 and 404 will not resolve by retrying. Fix the root cause first (parameter, key, credits, subscription, model id).
Wait for retry_after when you have itOtherwise back off: a few seconds, then longer. Hammering the API right after a 429 only brings more 429s.
Use an Idempotency-Key on sends, and check after a TIMEOUTThe key stops a retry from sending twice when we already had OnlyFans' answer. After a TIMEOUT the result is unknown: look the message up in /api/query before sending again.
Monitor your credit balanceCheck your remaining credits from the dashboard. Set up alerts before you run out to avoid interrupted service.