Scoped clients
Bind a client to a specific OnlyFans account to simplify multi-account workflows.
Most agencies manage multiple OnlyFans accounts. Instead of passing
auth on every request, create a scoped client that's bound to a
specific account.
Create a scoped client
Call .for(accountId) on the main client:
const client = new OfApiClient({
apiKey: process.env.BFL_API_KEY,
})
const alice = client.for("111111111")
const bob = client.for("222222222")Now alice and bob automatically authenticate as the correct
account on every request. No need to pass auth:
// Without scoped client — auth required every time
const [error, me] = await client.request("GET /users/me", {
auth: { onlyfansUserId: "111111111" },
})
// With scoped client — auth is automatic
const [error, me] = await alice.request("GET /users/me", {})Scoped client API
A ScopedClient exposes the same request() method as the main
client. The auth field becomes optional — if you omit it, the
scoped account ID is used. If you pass it, it overrides the default.
// Uses the scoped account
const [err, chats] = await alice.request("GET /chats", {
query: { limit: 20 },
})
// Override with a different account (rare, but supported)
const [err, chats] = await alice.request("GET /chats", {
auth: { onlyfansUserId: "333333333" },
query: { limit: 20 },
})Multi-account patterns
A common pattern is to iterate over your managed accounts and create scoped clients for each:
const managedAccounts = ["111111111", "222222222", "333333333"]
for (const accountId of managedAccounts) {
const account = client.for(accountId)
const [error, stats] = await account.request(
"GET /users/me/stats",
{},
)
if (!error) {
console.log(`Account ${accountId}: ${stats.subscribesCount} subs`)
}
}When to scope
Use scoped clients when you're making multiple requests for the same
account. For one-off requests, passing auth inline is fine.
| Pattern | Best for |
|---|---|
client.for(id) | Processing a single account's data in a function or job |
Inline auth | Ad-hoc requests where the account varies per call |
Loop + .for() | Batch operations across all managed accounts |