> ## Documentation Index
> Fetch the complete documentation index at: https://docs.originx.studio/llms.txt
> Use this file to discover all available pages before exploring further.

# JavaScript / TypeScript SDK

> The official @aniflixx/partner-sdk — authentication, catalog, streaming, search, and analytics with auto-retry and full TypeScript types.

The official SDK wraps the Partners API: it handles authentication, token caching and renewal, and retries with exponential backoff. Works in Node.js and the browser.

## Install

<CodeGroup>
  ```bash npm theme={null}
  npm install @aniflixx/partner-sdk
  ```

  ```bash pnpm theme={null}
  pnpm add @aniflixx/partner-sdk
  ```

  ```bash yarn theme={null}
  yarn add @aniflixx/partner-sdk
  ```
</CodeGroup>

## Quickstart

```javascript theme={null}
import AnimeSDK from '@aniflixx/partner-sdk'

const sdk = new AnimeSDK({
  apiKey: process.env.ORIGINX_API_KEY,
  apiSecret: process.env.ORIGINX_API_SECRET,
})

// authenticate() runs automatically on the first request,
// and the token is cached + renewed for you.
const catalog = await sdk.getContentCatalog()
console.log(`Found ${catalog.total_series} series`)
```

### Options

<Note>
  On a `401`, the SDK clears the cached token, re-authenticates, and retries once — so expiring tokens are handled transparently.
</Note>

## Methods

### getContentCatalog()

Every series + episodes you can access.

```javascript theme={null}
const catalog = await sdk.getContentCatalog()
catalog.content.forEach(s => console.log(`${s.title} — ${s.episodes.length} eps`))
```

### getSeries(seriesId)

```javascript theme={null}
const { series, episodes } = await sdk.getSeries('ser_8f2a91')
```

### getEpisodeStream(episodeId)

Resolves a video stream URL, or manga/webtoon page URLs.

```javascript theme={null}
const stream = await sdk.getEpisodeStream('ep_123')
if (stream.episode.type === 'video') {
  console.log('Play:', stream.stream_data.stream_url)
} else {
  stream.stream_data.pages.forEach((p, i) => console.log(`Page ${i + 1}: ${p.url}`))
}
```

### searchContent(query)

```javascript theme={null}
const { results, total } = await sdk.searchContent('sakura')
```

### getAnalytics()

```javascript theme={null}
const { stats, top_series } = await sdk.getAnalytics()
console.log('Total views:', stats.total_views)
```

### clearAuth()

Drops the cached token to force re-authentication on the next call.

## Error handling

The SDK throws `AnimeSDKError` for API errors, with `statusCode` and the raw `response`.

```javascript theme={null}
import AnimeSDK, { AnimeSDKError } from '@aniflixx/partner-sdk'

try {
  await sdk.getContentCatalog()
} catch (err) {
  if (err instanceof AnimeSDKError) {
    console.error(err.statusCode, err.message, err.response)
  } else {
    console.error('Network error', err)
  }
}
```

## TypeScript

```typescript theme={null}
import AnimeSDK, {
  ContentCatalogResponse,
  EpisodeStreamResponse,
  AnalyticsResponse,
} from '@aniflixx/partner-sdk'

const sdk = new AnimeSDK({ apiKey: process.env.KEY!, apiSecret: process.env.SECRET! })
const catalog: ContentCatalogResponse = await sdk.getContentCatalog()
```
