Building crunchy-api: A Modern TypeScript Client for Crunchyroll
· 4 min read

I love anime like Tokyo Ghoul, Attack on Titan, and Fullmetal Alchemist: Brotherhood. As a developer, naturally, I wanted to pull my watch history and currently watching lists into my own apps. The problem? I couldn't find a documented public API for the watch activity I wanted.
So, I built one.
Enter crunchy-api
I engineered crunchy-api, a fully-typed TypeScript client that seamlessly interacts with Crunchyroll's internal API. It handles token generation, session management, and parses enormous JSON payloads into strict, predictable TypeScript interfaces.
Here’s how you can use it to pull your own data with the current npm release, v0.2.0.
1. The Core Client
The foundation of the package is the CrunchyrollClient. The package is ESM-only and requires Node.js 18.17 or later. In a Next.js app, use it on the server, where your Crunchyroll credentials can stay private.
2. Authentication Contexts
For catalog calls such as getSeasonEpisodes(), use a separate bearer-only client. In v0.2.0, getAnonymousToken() returns a token, and setSession() makes it available to subsequent catalog calls.
To access your personal Watch History or custom Crunchylists, you need to use your refresh token cookie (etp_rt).
Use your own etp_rt cookie and keep it out of logs, source control, and NEXT_PUBLIC_* variables. The client stores the authenticated session in memory. When the access token expires, authenticate again.
3. Pulling Your Anime Data
Once authenticated, fetching data is as simple as calling a typed method. The SDK types the response, validates its envelope, and keeps upstream fields optional where the data can vary. getCurrentlyWatching() infers progress from the history page you request, so a single call can miss entries on later pages.
Public catalog calls can also fetch series details, list a series’ seasons, and fetch season metadata with getSeriesInfo(), getSeriesSeasons(), and getSeasonInfo().
Let's fetch season episodes of Wistoria S2 anonymously, directly pulling info using client.getSeasonEpisodes(seasonId) inside this Next.js server component:
1. Urban LegendThe secret society Psyren will lead humanity to paradise. Ageha picks up a strange phone card and ends up in a game of life and death.
2. TabooAgeha, Amamiya, and Hiryu reunite in the Psyren world. A voice thunders out, “To those who reach Psyren—the entire world shall be theirs!”
3. PSIAgeha and his friends have ended up in a death game. While heading for the finish line, before they can make it to safety, an unworldly monster calls a Taboo appears before them.
4. RecallIn a bid for survival, Ageha undergoes PSI training. Meanwhile, the actor Oboro and opportunistic Kabuto also receive phone cards.
5. Those GatheredA giant monster appears in the Psyren world where Ageha and the other Drifters have been teleported. Then, it turns out that the person standing in their path is Hiryu’s close friend, Tatsuo.
6. MemoryUnless they defeat Tatsuo, they won't make it to the goal. Ageha and Hiryu launch an attack on him together.You can also snag a dedicated episode instance, leveraging client.getEpisodeInfo(episodeId) just like this:
MemoryUnless they defeat Tatsuo, they won't make it to the goal. Ageha and Hiryu launch an attack on him together.S1 E6This embedded demo shows a saved list when the server has access. The labeled sample cards show what the components look like when live data is unavailable.
Building a Next.js Integration Harness
To prove out the package, I built a Next.js integration harness that runs on the server and invokes each package method. This ensures that features like force-dynamic API routes and React Server Components play nicely with the crunchy-api fetch implementations.
Because the returned data can be nested (e.g., episode info is sometimes wrapped in a panel object, and image arrays are deeply nested), I built a robust normalizer component:
For an anime tracker, Discord bot, or portfolio widget, the SDK gives you typed responses and a session you can reuse between calls.
Here is a live demo pulling my actual watch history right now, rendered natively in MDX using Server Components:
The Iceblade Sorcerer Shall Rule the WorldNow watching · EP 5 - The Boy Who Is the World’s Strongest Sorcerer Goes on a Date With That Girl in a Foreign Land
The Cold Sato-san is Only Sweet to MeNow watching · EP 6 - The Beach, a Cat, and Love Talk
PSYRENNow watching · EP 5 - Those Gathered
PSYRENEP 6 - Memory
Black CloverEP 179 - Yuno Grinberryall
Magical ExplorerEP 10 - Undies Dungeon
A Returner's Magic Should Be SpecialEP 21 - New Hope
OvergearedEP 10 - Perfect MetalWhat changed in v0.2.0
The original widget only needed the latest page of history. If I'm importing a larger collection, I can now use an async iterator to request each page as I need it.
There are iterators for history, Crunchylist items, and season episodes too. A page cap limits the amount of data pulled in one run. Calls accept an abort signal and a timeout override, and the SDK exposes typed errors for authentication, validation, cancellation, and API failures.
Try the Developer Studio
I built Developer Studio so you can browse the API reference, try sample responses, and export JSON without writing an integration first. Its hosted Connection tab also supports an optional account connection that uses a short-lived, encrypted HttpOnly session cookie.
Aniway uses the SDK for optional Crunchyroll sync. It’s the same idea that started this project: take the watch data I already have and use it somewhere that fits how I watch anime.
Install crunchy-api from npm, or read the source and API reference on GitHub.