Link stats, chats, messages, media
require "bundler/setup"
require "onlyfans"
only_fans_api = Onlyfans::Client.new(api_key: ENV["ONLYFANSAPI_API_KEY"])
# GET /api/{account}/tracking-links/{tracking_link_id}/stats
stats = only_fans_api.tracking_links.get_stats("12345678", account: "acct_XXXXXXXXXXXXX")
summary = stats.data.summary
puts("Clicks: #{summary.clicks_total} · Subs: #{summary.subs_total} · Spenders: #{summary.spenders_total}")
arps = summary.subs_total.to_i.zero? ? 0.0 : summary.revenue_total / summary.subs_total
puts(format("ARPS: $%.2f · Lifetime: $%.2f", arps, summary.revenue_total))
# Output:
# Clicks: 1240 · Subs: 300 · Spenders: 42
# ARPS: $12.40 · Lifetime: $3720.00require "bundler/setup"
require "onlyfans"
only_fans_api = Onlyfans::Client.new(api_key: ENV["ONLYFANSAPI_API_KEY"])
# GET /api/{account}/tracking-links/{tracking_link_id}/spenders
spenders = only_fans_api.tracking_links.list_spenders(
"12345678",
account: "acct_XXXXXXXXXXXXX",
limit: 50,
min_spend: 1
)
spenders.data.each do |fan|
puts("@#{fan.username} (#{fan.onlyfans_id}) spent $#{fan.revenue.total}")
end
# Output:
# @sarah_k (412938471) spent $189.0require "bundler/setup"
require "onlyfans"
only_fans_api = Onlyfans::Client.new(api_key: ENV["ONLYFANSAPI_API_KEY"])
# GET /api/{account}/chats
chats = only_fans_api.chats.list("acct_XXXXXXXXXXXXX", limit: "20", order: :recent)
chats.data.each do |chat|
puts("#{chat.fan.display_name}: #{chat.unread_messages_count} unread")
end
puts("Next page: #{chats._pagination&.next_page}")
# Output:
# Sarah: 3 unread
# Next page: https://app.fansapi.com/api/acct_XXXXXXXXXXXXX/chats?limit=20&offset=20require "bundler/setup"
require "onlyfans"
only_fans_api = Onlyfans::Client.new(api_key: ENV["ONLYFANSAPI_API_KEY"])
# GET /api/{account}/chats/{chat_id}/messages
messages = only_fans_api.chats.messages.list(
"123456789",
account: "acct_XXXXXXXXXXXXX",
limit: "10",
order: "desc"
)
messages.data.each do |message|
puts("[#{message.created_at}] #{message.is_sent_by_me ? "me" : "fan"}: #{message.text}")
end
# Output:
# [2026-09-04T18:22:41+00:00] me: Just posted something new for you 💜require "bundler/setup"
require "onlyfans"
only_fans_api = Onlyfans::Client.new(api_key: ENV["ONLYFANSAPI_API_KEY"])
# POST /api/{account}/chats/{chat_id}/messages
message = only_fans_api.chats.messages.send_(
"123456789",
account: "acct_XXXXXXXXXXXXX",
text: "Hey! Thanks for subscribing!",
media_files: ["ofapi_media_XXXXXXXXXXXXX"],
price: 0
)
puts("Message sent ##{message.data.id}")
# Output:
# Message sent #6182934517require "bundler/setup"
require "onlyfans"
only_fans_api = Onlyfans::Client.new(api_key: ENV["ONLYFANSAPI_API_KEY"])
# GET /api/{account}/media/download/{cdnUrl}
# Cached files 302-redirect to cdn.fansapi.com; the client follows the redirect.
cdn_url = "https://cdn2.onlyfans.com/files/x/y/z/file.jpg?Expires=..."
file = only_fans_api.media.download(cdn_url, account: "acct_XXXXXXXXXXXXX")
File.binwrite("file.jpg", file)
puts("Saved #{file.bytesize} bytes")
# Output:
# Saved 1834209 bytesAn SDK that feels at
home in Ruby
Idiomatic objects, flexible IO, and strong tooling support for growing codebases.
Ruby-native API
Readable method calls and objects that fit naturally into Ruby applications.
Yard + RBS + RBI / Sorbet
Discover classes and methods through comprehensive inline documentation.
Connection pooling
Reuse net/http connections efficiently through connection_pool.
The details that matter
after your first request
Resilient networking and predictable behavior are built into the client, so production code stays focused on your product.
Automatic retries
Recover from temporary connection, rate-limit, and server failures.
Configurable timeouts
Set client-wide defaults and override behavior for individual calls.
Structured errors
Handle authentication, validation, rate-limit, and server errors separately.
Raw responses
Access headers and underlying response information when you need it.
Environment authentication
Keep credentials out of source control using an environment variable.
Custom requests
Reach additional endpoints without abandoning the SDK client.
Everything you need
for the next step
Move from the quick start to complete endpoint details and source code.

Ruby 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.
