Skip to main content

Overview

The OnlyFans SDK provides comprehensive content management through three main modules with complete type safety and automatic parameter validation.

Posts

sdk.posts - Content creation, retrieval, and scheduling with type-safe parameters

Vault

sdk.vault - Media management and organization with validated operations

Upload

sdk.upload - File uploads with progress tracking and type validation

Why Use the SDK for Content Management?

Type-Safe Creation

Compile-time validation for all post parameters, media types, and scheduling options

Smart Validation

Automatic parameter checking ensures valid media IDs, price formats, and content restrictions

Posts Module

The Posts module handles post creation, retrieval, and management.

Methods

sdk.posts.getById(postId, options?)
method
Get a specific post by ID
sdk.posts.getAll(options?)
method
Get all posts from timeline
sdk.posts.create(postData, options?)
method
Create a new post

Example Usage

// Get a specific post
const result = await sdk.posts.getById("12345", {
  connectionId: "conn_abc123"
});

if (result.error) {
  console.error("Error:", result.error.message);
  return;
}

console.log("Post:", result.data);

// Get timeline posts
const timelineResult = await sdk.posts.getAll({
  connectionId: "conn_abc123",
  limit: 10,
  order: "publish_date_desc"
});

if (timelineResult.data) {
  console.log("Posts:", timelineResult.data);
}

Vault Module

The Vault module manages your media library and storage.

Methods

sdk.vault.getAll(options?)
method
Get all media items from vault
sdk.vault.getById(mediaId, options?)
method
Get a specific media item by ID
sdk.vault.delete(mediaId, options?)
method
Delete a media item from vault

Example Usage

// Get all vault media
const vaultResult = await sdk.vault.getAll({
  connectionId: "conn_abc123",
  limit: 50,
  type: "photo"
});

if (vaultResult.data) {
  console.log("Vault media:", vaultResult.data);
}

// Get specific media item
const mediaResult = await sdk.vault.getById("media_123", {
  connectionId: "conn_abc123"
});

// Delete media item
const deleteResult = await sdk.vault.delete("media_123", {
  connectionId: "conn_abc123"
});

Upload Module

The Upload module handles file uploads to the platform.

Methods

sdk.upload.uploadFile(file, options?)
method
Upload a file to the platform
sdk.upload.getUploadProgress(uploadId)
method
Get upload progress for a specific upload

Example Usage

// Upload from file input
const fileInput = document.getElementById('fileInput') as HTMLInputElement;
const file = fileInput.files[0];

const uploadResult = await sdk.upload.uploadFile(file, {
  type: "photo",
  description: "Profile picture",
  connectionId: "conn_abc123"
});

if (uploadResult.error) {
  console.error("Upload failed:", uploadResult.error.message);
  return;
}

console.log("Upload successful:", uploadResult.data);

Integration Patterns

Content Workflow

// Complete content creation workflow
async function createContentPost() {
  try {
    // 1. Upload media files
    const imageUpload = await sdk.upload.uploadFile(imageFile, {
      type: "photo",
      connectionId: "conn_abc123"
    });
    
    if (imageUpload.error) {
      throw new Error(`Upload failed: ${imageUpload.error.message}`);
    }
    
    // 2. Create post with uploaded media
    const postResult = await sdk.posts.create({
      text: "Check out my new content!",
      price: 10.00,
      mediaItems: [imageUpload.data.id]
    }, {
      connectionId: "conn_abc123"
    });
    
    if (postResult.error) {
      throw new Error(`Post creation failed: ${postResult.error.message}`);
    }
    
    console.log("Post created successfully:", postResult.data);
    
  } catch (error) {
    console.error("Content creation failed:", error);
  }
}

Vault Management

// Organize vault content
async function organizeVault() {
  const vaultResult = await sdk.vault.getAll({
    connectionId: "conn_abc123",
    limit: 100
  });
  
  if (vaultResult.data) {
    // Filter old unused media
    const oldMedia = vaultResult.data.filter(item => {
      const uploadDate = new Date(item.createdAt);
      const monthsOld = (Date.now() - uploadDate.getTime()) / (1000 * 60 * 60 * 24 * 30);
      return monthsOld > 6;
    });
    
    // Clean up old media
    for (const media of oldMedia) {
      await sdk.vault.delete(media.id, {
        connectionId: "conn_abc123"
      });
    }
  }
}

Error Handling

Content management operations can fail for various reasons. Always handle errors appropriately:
const result = await sdk.posts.create(postData, options);

if (result.error) {
  switch (result.error.type) {
    case 'bad_request':
      console.error("Invalid post data:", result.error.details);
      break;
    case 'unauthorized':
      console.error("Authentication required");
      break;
    case 'forbidden':
      console.error("Insufficient permissions");
      break;
    default:
      console.error("Unexpected error:", result.error.message);
  }
}

Best Practices

File Upload Optimization

  • Compress images before upload to reduce file size
  • Validate file types and sizes before uploading
  • Use progress tracking for large files
  • Implement retry logic for failed uploads

Content Organization

  • Tag content appropriately for easy discovery
  • Use descriptive filenames for vault organization
  • Regular cleanup of unused media to save storage
  • Batch operations when possible to improve performance

Performance Tips

  • Paginate large content lists to avoid memory issues
  • Cache frequently accessed media locally
  • Use appropriate image sizes for different contexts
  • Implement lazy loading for media-heavy interfaces