Link stats, chats, messages, media
<?php
use Onlyfansapi\Client;
$client = new Client(apiKey: getenv('ONLYFANSAPI_API_KEY'));
// GET /api/{account}/tracking-links/{tracking_link_id}/stats
$stats = $client->trackingLinks->getStats('123456', account: 'acct_XXXXXXXXXXXXX');
$summary = $stats->data->summary;
$arps = $summary->subsTotal ? $summary->revenueTotal / $summary->subsTotal : 0;
echo "Clicks: {$summary->clicksTotal} · Subs: {$summary->subsTotal}", PHP_EOL;
echo "Spenders: {$summary->spendersTotal}", PHP_EOL;
printf("ARPS: $%.2f · Lifetime: $%.2f", $arps, $summary->revenueTotal);
// Output:
// Clicks: 1240 · Subs: 300
// Spenders: 42
// ARPS: $12.40 · Lifetime: $3720.00<?php
use Onlyfansapi\Client;
$client = new Client(apiKey: getenv('ONLYFANSAPI_API_KEY'));
// GET /api/{account}/tracking-links/{tracking_link_id}/spenders
$spenders = $client->trackingLinks->listSpenders(
'123456',
account: 'acct_XXXXXXXXXXXXX',
limit: 50,
minSpend: 1,
);
foreach ($spenders->data as $fan) {
printf("@%s spent $%.2f%s", $fan->username, $fan->revenue->total, PHP_EOL);
}
// Output:
// @sarah_k spent $189.00<?php
use Onlyfansapi\Client;
use Onlyfansapi\Chats\ChatListParams\Order;
$client = new Client(apiKey: getenv('ONLYFANSAPI_API_KEY'));
// GET /api/{account}/chats
$chats = $client->chats->list('acct_XXXXXXXXXXXXX', limit: '10', order: Order::RECENT);
foreach ($chats->data as $chat) {
echo "@{$chat->fan->username} · unread: {$chat->unreadMessagesCount}", PHP_EOL;
echo " {$chat->lastMessage->text}", PHP_EOL;
}
// Output:
// @sarah_k · unread: 3
// Hey, are you around?<?php
use Onlyfansapi\Client;
$client = new Client(apiKey: getenv('ONLYFANSAPI_API_KEY'));
// GET /api/{account}/chats/{chat_id}/messages
$messages = $client->chats->messages->list(
'987654321',
account: 'acct_XXXXXXXXXXXXX',
limit: '20',
order: 'desc',
);
foreach ($messages->data as $message) {
echo "[{$message->createdAt}] {$message->text}", PHP_EOL;
}
// Output:
// [2026-09-04T18:22:41+00:00] Just posted something new for you 💜<?php
use Onlyfansapi\Client;
$client = new Client(apiKey: getenv('ONLYFANSAPI_API_KEY'));
// POST /api/{account}/chats/{chat_id}/messages
$message = $client->chats->messages->send(
'987654321',
account: 'acct_XXXXXXXXXXXXX',
text: 'Hey! Thanks for subscribing 💜',
mediaFiles: ['ofapi_media_XXXXXXXXXXXXX'],
price: 0,
);
echo "Message sent #{$message->data->id}", PHP_EOL;
// Output:
// Message sent #6182934517<?php
use Onlyfansapi\Client;
$client = new Client(apiKey: getenv('ONLYFANSAPI_API_KEY'));
// GET /api/{account}/media/download/{cdn_url}
// Returns the file bytes (or follows a 302 to cdn.fansapi.com when cached).
$cdnUrl = 'https://cdn2.onlyfans.com/files/…/photo.jpg?Expires=…';
$bytes = $client->media->download($cdnUrl, account: 'acct_XXXXXXXXXXXXX');
file_put_contents(__DIR__ . '/photo.jpg', $bytes);
echo 'Saved ' . strlen($bytes) . ' bytes', PHP_EOL;
// Output:
// Saved 1834209 bytesClean integrations for
modern PHP
Expressive calls, structured responses, and dependable behavior in production.
Modern PHP
Built for PHP 8.1+ with current language features and conventions.
Configurable retries
Tune retries globally or override them for an individual request.
Focused exceptions
Handle connection, timeout, authentication, rate-limit, and API errors separately.
Turn API access into useful creator tools
Use one consistent client across dashboards, internal operations, and automated workflows.
Analytics Dashboards
Bring account and performance data into reporting experiences your team can act on.
Media Workflows
Build upload flows around familiar file, stream, and byte-based objects.
Internal Automation
Build upload flows around familiar file, stream, and byte-based objects.
Multi-account tools
Create focused interfaces for teams working across multiple connected accounts.
Reporting Pipelines
Move structured API responses into warehouses, spreadsheets, and custom reports.
Custom integrations
Extend the typed client with custom requests when your product needs more flexibility.
Everything you need
for the next step
Move from the quick start to complete endpoint details and source code.

PHP SDK docs
Installation, configuration, examples, and language-specific guidance.

API reference
Explore endpoints, parameters, response schemas, and error details.

Source on GitHub
Review the SDK source, releases, examples, and contribution guide.
