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?)
Get a specific post by ID
The ID of the post to retrieve
Connection ID for Access mode
Session object for Direct mode
Whether post can be purchased
sdk.posts.getAll(options?)
Get all posts from timeline
Number of posts to retrieve (default: 20)
Sort order: “publish_date_desc” | “publish_date_asc”
Connection ID for Access mode
Session object for Direct mode
sdk.posts.create(postData, options?)
Create a new post
Schedule date (ISO string)
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);
}
// Get a specific post
const result = await sdk.posts.getById("12345", {
session: sessionData
});
// Create a new post
const createResult = await sdk.posts.create({
text: "Hello world!",
price: 0,
mediaItems: ["media_123", "media_456"]
}, {
session: sessionData
});
Vault Module
The Vault module manages your media library and storage.
Methods
sdk.vault.getAll(options?)
Get all media items from vault
Number of items to retrieve
Media type filter: “photo” | “video” | “audio”
Connection ID for Access mode
Session object for Direct mode
sdk.vault.getById(mediaId, options?)
Get a specific media item by ID
Duration (for video/audio)
sdk.vault.delete(mediaId, options?)
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?)
Upload a file to the platform
file
File | Buffer | string
required
The file to upload (File object, Buffer, or file path)
Media type: “photo” | “video” | “audio”
Connection ID for Access mode
Session object for Direct mode
Duration (for video/audio)
sdk.upload.getUploadProgress(uploadId)
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);
import fs from 'fs';
// Upload from file path
const filePath = './image.jpg';
const fileBuffer = fs.readFileSync(filePath);
const uploadResult = await sdk.upload.uploadFile(fileBuffer, {
type: "photo",
description: "Content image",
session: sessionData
});
if (uploadResult.data) {
console.log("Media ID:", uploadResult.data.id);
}
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
- 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