Fansly APIFansly API
Fansly API Quickstart: Authentication, Endpoints, and HMAC Webhook Verification

Fansly API Quickstart: Authentication, Endpoints, and HMAC Webhook Verification

By Anna

Article summary

How do I authenticate with the Fansly API and verify HMAC webhooks?

The creator economy has transitioned from isolated social media profiles into high-throughput digital enterprises. On platforms hosting upwards of 130 million registered users, managing multiple creator accounts manually or via fragile reverse-engineered scraping scripts is no longer a viable strategy for agencies and enterprise tooling providers. This quickstart guide serves as comprehensive API documentation for developers looking to build scalable CRMs, mass-messaging tools, and revenue dashboards.

Whether you are integrating natively or using workflow orchestrators, understanding how to manage API keys, process integer-based currency formats, and securely verify real-time API webhooks is critical for a production-grade deployment.

What is the Fansly API?

The Fansly API is an enterprise-grade developer platform engineered by Fans Holdings OÜ that replaces headless browser automation with official, stable infrastructure. Built for creator management agencies and SaaS platforms, it exposes over 200 live REST API endpoints covering messaging, CRM profiles, transactions, and media vaults.

With a production track record of supporting over 5,000 connected creator accounts and processing more than 150 million requests with zero platform bans, the Fansly API provides a secure environment for account scaling. It also features a real-time push architecture via cryptographically signed webhooks, eliminating the credit-intensive need for continuous polling.

Step 1: API Authentication and Key Management

Secure API authentication is the foundation of your integration. The platform utilizes bearer token authentication, which requires developers to pass a secure token in the HTTP headers of every request.

Generating and Scoping API Keys

To interact with the platform, you must authenticate your HTTP clients using API keys generated from your developer dashboard. According to the Fansly API Integration Guide, you should follow these steps:

  1. Register an Account: Create an account on the Fansly API platform. New developers receive a sandbox allocation of 10 free credits to test live connections.
  2. Create an API Key: Open app.onlyfansapi.com/api-keys and generate a key. Keys are not scoped: every key can call every endpoint for every account connected to your team, so create one key per integration and rotate any key you hand to an external developer.
  3. Secure Your Secrets: Store your API keys in a secure runtime environment, such as AWS Secrets Manager or encrypted .env files. Never commit them to public version control.

Standard Request Headers

Every inbound request requires specific HTTP headers to define the payload type, authenticate the client, and target specific creator accounts.

Header Name Example Requirement Description
Authorization Bearer YOUR_API_KEY Required Your developer platform secret API key.
Content-Type application/json Required (POST/PUT) Declares JSON formatting for payloads.
Accept application/json Required Ensures responses are returned as JSON.

cURL Authentication Example:

curl -X GET "https://app.onlyfansapi.com/api/fansly/fansly_acct_XXXXXXXXXXXXXXX/chats" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Accept: application/json"

Step 2: Navigating Core API Endpoints

Once authenticated, developers gain access to over 200 live API endpoints spanning six primary resource domains. These endpoints allow you to orchestrate complex agency workflows programmatically.

  • Accounts & Sessions: Endpoints like /api/v1/accounts connect creator accounts via 2FA and inspect proxy session health.
  • Messaging: Use /api/v1/chats and /api/v1/messages/mass to read direct messages, execute real-time chatbot replies, or queue bulk PPV blasts.
  • Fans & CRM: Query fan spend histories, subscription dates, and engagement tiers via /api/v1/fans.
  • Financials: Reconcile gross revenue, platform cuts, net payouts, and tracking link conversions using /api/v1/earnings/summary.
  • Media & Vault: Upload multimedia files (up to 1GB via remote URL) and publish tier-locked feed posts through /api/v1/vault/media.

Step 3: Financial Data Integrity (The Millidollar Format)

A common integration pitfall in creator-economy platforms is the mishandling of currency. Standard IEEE 754 floating-point operations (like 0.1 + 0.2 in JavaScript) introduce precision drift, which compounds into material accounting errors over thousands of PPV unlocks and tips.

To ensure financial data integrity, Fansly represents currency in thousandths of a dollar (millidollars).

  • $1.00 USD = 1000
  • $5.00 USD = 5000
  • $15.50 USD = 15500
  • $0.05 USD (5 cents) = 50

TypeScript Conversion Example

When building dashboards, always round your conversions to avoid intermediate representation anomalies:

export class FanslyCurrency {
  public static toMillidollars(dollars: number | string): number {
    const parsed = typeof dollars === 'string' ? parseFloat(dollars) : dollars;
    if (isNaN(parsed) || !isFinite(parsed)) throw new TypeError('Invalid amount');
    return Math.round(parsed * 1000);
  }
 
  public static toFormattedUSD(millidollars: number): string {
    return new Intl.NumberFormat('en-US', {
      style: 'currency',
      currency: 'USD',
    }).format(millidollars / 1000);
  }
}

Step 4: HTTP Status Codes and Error Handling

The platform complies with standard RFC 7231 HTTP response codes. According to Fansly API Pricing and RPM Architecture, handling rate limits (429) is especially critical depending on your plan tier (1,000 RPM for Basic vs. 5,000 RPM for Pro).

HTTP Code Error Code Recommended Recovery Action
400 INVALID_PAYLOAD Validate payload against endpoint schema.
401 UNAUTHORIZED Verify Authorization: Bearer <key> header.
403 INSUFFICIENT_PERMISSIONS Re-issue API key with correct scopes via the dashboard.
429 RATE_LIMIT_EXCEEDED Honor Retry-After header; implement exponential backoff.
500 INTERNAL_UPSTREAM_ERROR Log request_id and open automated escalation via support.

Step 5: Implementing a Real-Time API with HMAC Webhooks

Transitioning from continuous polling to a real-time API push architecture yields dramatic financial and performance advantages. According to the Fansly Webhooks Guide, polling an active 20-creator roster once a minute burns roughly 28,800 credits daily. Conversely, webhooks cost just 1 credit per 100 events and deliver data within sub-second latencies.

Webhook Security and Signature Verification

When a webhook event (like tip.received or message.received) fires, the payload is sent via a POST request to your registered HTTPS URL. To prove the event originated from Fansly, it includes an X-Fansly-Signature header computed via HMAC-SHA256.

Security Mandate: You must evaluate the HMAC hash against the raw, unparsed string buffer of the request body. Furthermore, to prevent timing attacks as outlined in RFC 2104, comparisons must run in constant time.

Node.js / Express Verification Reference

import express, { Request, Response } from 'express';
import { createHmac, timingSafeEqual } from 'crypto';
 
const app = express();
 
// Capture raw body buffer for verification
app.use(express.json({
  verify: (req: any, _res, buf) => {
    req.rawBody = buf;
  }
}));
 
const WEBHOOK_SECRET = process.env.FANSLY_WEBHOOK_SECRET;
const processedEvents = new Set<string>();
 
app.post('/api/fansly/webhook', (req: Request, res: Response): any => {
  const signature = req.headers['x-fansly-signature'] as string;
  const rawBody = (req as any).rawBody;
 
  if (!signature || !rawBody) return res.status(400).send('Missing signature');
 
  // 1. Calculate expected HMAC-SHA256 hash
  const computedHash = createHmac('sha256', WEBHOOK_SECRET)
    .update(rawBody)
    .digest('hex');
 
  // 2. Constant-time signature validation
  const signatureBuffer = Buffer.from(signature, 'utf8');
  const computedBuffer = Buffer.from(computedHash, 'utf8');
 
  if (signatureBuffer.length !== computedBuffer.length || !timingSafeEqual(signatureBuffer, computedBuffer)) {
    return res.status(401).send('Signature verification failed');
  }
 
  // 3. Prevent replay attacks via idempotency keys
  const event = req.body;
  const idempotencyKey = event.idempotencyKey || event.id;
 
  if (processedEvents.has(idempotencyKey)) {
    return res.status(200).json({ status: 'duplicate_ignored' });
  }
  processedEvents.add(idempotencyKey);
 
  // Process event and acknowledge quickly
  return res.status(200).json({ received: true });
});

Conclusion

Deploying high-performance creator management tools requires robust API documentation and secure practices. By properly scoping API keys, adhering to the millidollar standard for financial data, and establishing a secure real-time API connection using HMAC webhook verification, you can bypass the unreliability of scraping scripts. Leveraging the extensive library of API endpoints provided by the Fansly platform ensures that your agency infrastructure scales efficiently, securely, and profitably.

Ready to start building on top of Fansly?

Start for free