A simple TypeScript wrapper for the apibay.org API (The Pirate Bay).
npm install apibay.org
# or
pnpm add apibay.org
# or
yarn add apibay.orgimport { createApiBay } from 'apibay.org';
const apibay = createApiBay();With options:
const apibay = createApiBay({
baseUrl: 'https://apibay.org', // default, use a mirror if needed
transform: true, // validate and transform responses with Zod
});When transform: true is set, all responses are validated against Zod schemas and types are coerced (e.g. added becomes a Date, numeric strings become numbers). If validation fails, an error is thrown.
const results = await apibay.search({ q: 'ubuntu' });
// with category filter
const results = await apibay.search({ q: 'ubuntu', cat: 300 });// All categories
const top100 = await apibay.getTop100('all');
// Specific category
const top100 = await apibay.getTop100(207); // HD Movies
// Recently added
const recent = await apibay.getRecent();const details = await apibay.getDetails(12345678);
console.log(details.name);
console.log(details.descr);
console.log(details.seeders);const torrents = await apibay.getByUser('username');
// with pagination
const page2 = await apibay.getByUser('username', 1);apibay.setBaseUrl('https://piratebay-mirror.example.com');| Method | Description |
|---|---|
search(payload) |
Search torrents by query and optional category |
getTop100(category) |
Get top 100 torrents for a category, 'all', or 'recent' |
getRecent() |
Get the 100 most recently added torrents |
getDetails(id) |
Get detailed info for a torrent by ID |
getByUser(username, page?) |
Get torrents uploaded by a user |
getBaseUrl() |
Get the current base URL |
setBaseUrl(url) |
Set a custom base URL or mirror |
pnpm install
pnpm test
pnpm build