# OnlyFans API SDKs for TypeScript, Python, PHP & Ruby

> Build creator products with official, production-ready SDKs for Python, TypeScript, PHP, and Ruby. Pick your stack and make your first request in minutes.

Every SDK wraps the same REST API (base URL `https://app.fansapi.com/api/{account}/...`, 320+ endpoints) with the conventions of its language. Authenticate with the `ONLYFANSAPI_API_KEY` environment variable or pass the key to the client constructor.

## Choose the SDK that fits your stack

| Language | Install | Runtime | Page | Source |
| --- | --- | --- | --- | --- |
| TypeScript | `npm install @onlyfansapi/onlyfans-sdk` | Node.js, Deno, Bun | https://fansapi.com/sdk/typescript | https://github.com/onlyfansapi/onlyfansapi-typescript-sdk |
| Python | `pip install onlyfans` | Python 3.9+, sync & async | https://fansapi.com/sdk/python | https://github.com/onlyfansapi/onlyfansapi-python |
| PHP | `composer require onlyfansapi/onlyfansapi-php` | PHP 8.1+ | https://fansapi.com/sdk/php | https://github.com/onlyfansapi/onlyfansapi-php |
| Ruby | `bundle add onlyfans --version "~> 0.2.0"` | Ruby 3.2+ | https://fansapi.com/sdk/ruby | https://github.com/onlyfansapi/onlyfansapi-ruby |

- **Python** — Typed sync and async clients for Python 3.9+.
- **TypeScript** — First-class TypeScript types for modern Node.js.
- **PHP** — Named parameters and value objects for PHP 8.1+.
- **Ruby** — Thread-safe client gem with connection pooling and RBS/RBI types.

## Your first OnlyFans API SDK call in four languages

Install the package, set your API key and list the OnlyFans accounts connected to it. The same call in TypeScript, Python, PHP and Ruby.

### TypeScript

Run `npm install @onlyfansapi/onlyfans-sdk`, set `ONLYFANSAPI_API_KEY` and await your first call. Works in Node.js, Deno and Bun, and drops into Next.js, Express or Hono.

```typescript
import OnlyFansAPI from '@onlyfansapi/onlyfans-sdk';

// Reads ONLYFANSAPI_API_KEY from the environment
const client = new OnlyFansAPI();

// GET /api/accounts: every OnlyFans account connected to your API key
const accounts = await client.accounts.list();

for (const account of accounts) {
  console.log(`${account.id} · @${account.onlyfans_username}`);
}
```

### Python

Run `pip install onlyfans`, then `import onlyfansapi`. One client for sync code and one for async, on Python 3.9 or newer, ready for Django, FastAPI, Flask or a Celery worker.

```python
from onlyfansapi import OnlyFansAPI

# Reads ONLYFANSAPI_API_KEY from the environment
client = OnlyFansAPI()

# GET /api/accounts: every OnlyFans account connected to your API key
accounts = client.accounts.list()

for account in accounts:
    print(f"{account.id} · @{account.onlyfans_username}")
```

### PHP

Run `composer require onlyfansapi/onlyfansapi-php` with any PSR-18 HTTP client, such as Guzzle. Built for PHP 8.1+, with named arguments, enums and typed responses that fit Laravel.

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Onlyfansapi\Client;

// Reads ONLYFANSAPI_API_KEY from the environment
$client = new Client();

// GET /api/accounts: every OnlyFans account connected to your API key
$accounts = $client->accounts->list();

foreach ($accounts as $account) {
  echo "{$account->id} · @{$account->onlyfansUsername}", PHP_EOL;
}
```

### Ruby

Run `bundle add onlyfans` and `require "onlyfans"`. A thread-safe client for Ruby 3.2+, with RBS and RBI types, that works from a Rails controller or a Sidekiq job.

```ruby
require "onlyfans"

# Reads ONLYFANSAPI_API_KEY from the environment
client = Onlyfans::Client.new

# GET /api/accounts: every OnlyFans account connected to your API key
accounts = client.accounts.list

accounts.each do |account|
  puts "#{account.id} · @#{account.onlyfans_username}"
end
```

## What teams build with the OnlyFans API

- **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** — Connect recurring account operations to your own backend jobs and business logic.
- **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.

## The details that matter after your first request

Resilient networking and predictable behavior are built into every client, so production code stays focused on your product.

- **Automatic Retries** — Recover from temporary connection, rate-limit, and server failures. Connection errors, timeouts, 429s, and 5xx responses are retried twice with exponential backoff.
- **Structured Errors** — Handle authentication, validation, rate-limit, and server errors separately.
- **Environment Authentication** — Keep credentials out of source control using the `ONLYFANSAPI_API_KEY` environment variable.
- **Configurable Timeouts** — Set client-wide defaults and override behavior for individual calls.

## Questions before you start

### Which OnlyFans API SDK should I use?

Use the one that matches your backend. All four SDKs call the same API with the same resources, so the choice comes down to your stack: TypeScript for Node.js, Deno and Bun, Python for Django, FastAPI and Flask, PHP for Laravel, and Ruby for Rails. If your team runs more than one language, each service can use its own SDK against the same API key.

### How many endpoints do the SDKs cover?

Every SDK wraps the full REST API, more than 320 endpoints: accounts, chats and messages, fans, media, posts, tracking links, payouts, data exports and more. When a new endpoint ships before the SDK update, custom requests let you call it right away.

### Where do I install the SDKs from?

From the package manager you already use: npm for TypeScript, PyPI for Python, Packagist for PHP and RubyGems for Ruby. The source code of every SDK is public on GitHub, so you can read exactly what runs in your application.

### Do the SDKs cost extra?

No. The SDKs are free to install. Your requests run on your Fans API plan, and the Free plan includes 100 welcome credits, so you can make your first OnlyFans API request before you pick a paid plan.

### Can I use an SDK for more than one OnlyFans account?

Yes. One API key can reach every account connected to your team. Pass the account ID on each call, which makes it straightforward to build agency dashboards, reporting jobs and tools that run across many creators.

### Does OnlyFans have an official public API?

OnlyFans itself does not offer a public developer API. Fans API is an independent platform that provides reliable API access to OnlyFans accounts, with official SDKs for TypeScript, Python, PHP, and Ruby.

### How do I authenticate?

Set the `ONLYFANSAPI_API_KEY` environment variable or pass your API key when creating the client. Environment-based configuration keeps credentials out of source control.

### Does the SDK include request and response types?

Yes. Each SDK follows the conventions of its language and includes structured request and response models: TypeScript definitions, Python TypedDicts and Pydantic models, PHP value objects, and Ruby RBS/RBI types.

### What happens when a request fails?

Failed requests raise a typed error you can catch — authentication, rate-limit, validation, connection, and server errors separately. Connection errors, timeouts, 429s, and 5xx responses are retried twice automatically with exponential backoff.

### Can I upload files?

Yes. Every SDK supports media uploads from file paths, streams, or raw contents in the forms native to its language.

### Can I call an endpoint that is not documented yet?

Yes. Every SDK supports custom requests to undocumented endpoints and parameters while keeping authentication and retries.

## Links

- Get your API key: https://app.fansapi.com/register
- API reference: https://docs.fansapi.com/api-reference/overview
- OpenAPI spec: https://app.fansapi.com/scribe-docs/openapi.json
- Pricing: https://fansapi.com/pricing