Skip to main content

Prerequisites

Before installing the OnlyFans SDK, ensure your development environment meets these requirements:
  • Node.js — Minimum version 16.0 or higher.
    # Check your Node.js version
    node --version
    
    # Should output v16.0.0 or higher
    
  • TypeScript — Recommended 4.5 or higher for full type support.
    # Install TypeScript globally if needed
    npm install -g typescript
    
    # Check TypeScript version
    tsc --version
    
  • Package Manager — Use any modern option:
    • npm (bundled with Node.js)
    • pnpm (recommended for speed)
    • yarn (v1 or v2+)

Installation

Choose your preferred package manager to install the OnlyFans SDK:
npm install @ofauth/onlyfans-sdk
The SDK package includes TypeScript definitions out of the box, so no additional @types/ packages are needed.

Basic Setup

1. Import the SDK

import OFSDK from "@ofauth/onlyfans-sdk"

2. Initialize the SDK

The SDK supports three different modes. Choose the one that best fits your use case:
  • Access Mode (recommended) — Managed API calls through OFAuth, ideal for most applications.
    import OFSDK from "@ofauth/onlyfans-sdk"
    
    const sdk = new OFSDK({
      mode: "access",
      ofauthApiKey: process.env.OFAUTH_API_KEY,
      debugLog: false // Enable for development
    })
    
    Access mode uses OFAuth’s managed infrastructure to handle OnlyFans API complexities automatically.
  • Direct Mode — Full control over API requests, session management, and local debugging without usage costs.
    import OFSDK from "@ofauth/onlyfans-sdk"
    
    const sdk = new OFSDK({
      mode: "direct",
      ofauthApiKey: process.env.OFAUTH_API_KEY, // Required for request signing
      debugLog: true // Helpful for debugging direct API calls
    })
    
    Direct mode requires manual session management and handling of OnlyFans API changes.
  • Custom Mode — Enterprise setups with custom proxy infrastructure and routing requirements.
    import OFSDK from "@ofauth/onlyfans-sdk"
    
    const sdk = new OFSDK({
      mode: "custom",
      customOptions: {
        baseUrl: "https://your-api-proxy.com",
        signRequests: false, // Set to true if using OFAuth signing
        beforeRequest: (url, request) => {
          // Add custom headers or modify requests
          request.headers = {
            ...request.headers,
            "X-Custom-Header": "your-value"
          }
          return request
        }
      },
      ofauthApiKey: process.env.OFAUTH_API_KEY // Required if signRequests: true
    })
    
    Custom mode is perfect for enterprise environments where requests need to go through internal proxies or custom infrastructure.

Verify Installation

Create a simple test to verify the SDK is working correctly:
test-sdk.ts
import OFSDK from "@ofauth/onlyfans-sdk"

async function testSDK() {
  try {
    // Initialize SDK
    const sdk = new OFSDK({
      mode: "access",
      ofauthApiKey: process.env.OFAUTH_API_KEY,
      debugLog: true
    })
    
    console.log("✅ SDK initialized successfully")
    
    // Test a simple operation (requires valid connection)
    // This will fail if no valid connection exists, which is expected
    const { data, error } = await sdk.link.connections.getAll({
      limit: 1
    })
    
    if (error && error.type === "unauthorized") {
      console.log("✅ SDK is working (authentication required for actual data)")
    } else if (data) {
      console.log("✅ SDK is working and authenticated")
    } else {
      console.error("❌ Unexpected error:", error)
    }
    
  } catch (error) {
    console.error("❌ SDK initialization failed:", error.message)
  }
}

testSDK()
Run the test:
npx tsx test-sdk.ts
# or if using regular JavaScript
node test-sdk.js

Confirm Platform Configuration

Use the Account API to verify that your API key and platform metadata are set up correctly. The whoami endpoint returns only general information about your organization.
curl -s https://api.ofauth.com/v2/account/whoami \
  -H "apikey: $OFAUTH_API_KEY" \
response
{
  "platform": {
    "id": "plat_123",
    "name": "Acme Analytics",
    "benefits": {
      "access": true,
      "link": true
    },
    "permissions": ["profile:read"],
    "allowedOrigins": ["https://app.example.com"],
    "maxRateLimits": {
      "access": {
        "capacity": 120,
        "refillRate": 1
      }
    }
  }
}
The account response is safe to expose in internal dashboards. It never returns secrets—only plan-level metadata for the authenticated platform.

Next Steps

Need Help? If you encounter issues during installation, check our troubleshooting guide or reach out to support.