<a href="https://github.com/ghoshRitesh12/aniwatch-api">
<img
src="https://raw.githubusercontent.com/ghoshRitesh12/aniwatch-api/refs/heads/main/public/img/hianime_v2.png"
alt="aniwatch_logo"
width="175"
height="175"
decoding="async"
fetchpriority="high"
/>
</a>
Aniwatch API
A free RESTful API serving anime information from <a href="https://hianimez.to" target="_blank">hianimez.to</a>
<a
href="https://github.com/ghoshRitesh12/aniwatch-api/issues/new?assignees=ghoshRitesh12&labels=bug&template=bug-report.yml"
>
Bug report
</a>
·
<a
href="https://github.com/ghoshRitesh12/aniwatch-api/issues/new?assignees=ghoshRitesh12&labels=enhancement&template=feature-request.md"
>
Feature request
</a>
[!IMPORTANT]
- There was previously a hosted version of this API for showcasing purposes only, and it was misused; since then, there have been no other hosted versions. It is recommended to deploy your own instance for personal use by customizing the API as you need it to be.
- This API is just an unofficial API for hianimez.to and is in no other way officially related to the same.
- The content that this API provides is not mine, nor is it hosted by me. These belong to their respective owners. This API just demonstrates how to build an API that scrapes websites and uses their content.
Clone the repository and move into the directory.
bash
git clone https://github.com/ghoshRitesh12/aniwatch-api.git
cd aniwatch-api
Install all the dependencies.
bash
npm i #or yarn install or pnpm i
Start the server!
bash
npm start #or yarn start or pnpm start
Now the server should be running on http://localhost:4000
The Docker image is available at The GitHub Container Registry.
Run the following commands to pull and run the docker image.
docker run -d --name aniwatch-api -p 4000:4000 ghcr.io/ghoshritesh12/aniwatch
The above command will start the server on port 4000. You can access the server at http://localhost:4000, and you can also change the port by changing the -p option to -p <port>:4000.
The -d flag runs the container in detached mode, and the --name flag is used to name the container that's about to run.
Currently this API supports parsing of only one custom header, and more may be implemented in the future to accommodate varying needs.
Aniwatch-Cache-Expiry: This custom request header is used to specify the cache expiration duration in seconds (defaults to 300 or 5 mins if the header is missing). The ANIWATCH_API_REDIS_CONN_URL env is required for this custom header to function as intended; otherwise, there's no point in setting this custom request header. A response header of the same name is also returned with the value set to the cache expiration duration in seconds if ANIWATCH_API_REDIS_CONN_URL env is set.More info can be found in the .env.example file, where envs' having a value that is contained within < > angled brackets, commented out or not, are just examples and should be replaced with relevant ones.
ANIWATCH_API_PORT: Port number of the aniwatch API.ANIWATCH_API_WINDOW_MS: Duration to track requests for rate limiting (in milliseconds).ANIWATCH_API_MAX_REQS: Maximum number of requests in the ANIWATCH_API_WINDOW_MS time period.ANIWATCH_API_CORS_ALLOWED_ORIGINS: Allowed origins, separated by commas and no spaces in between (CSV).ANIWATCH_API_DEPLOYMENT_ENV: The deployment environment of the Aniwatch API. Many configurations depend on this env, rate limiting being one of them. It must be set incase of serverless deployments; otherwise, you may run into weird issues. Possible values: 'nodejs' | 'docker' | 'vercel' | 'render' | 'cloudflare-workers'.ANIWATCH_API_HOSTNAME: Set this to your api instance's hostname to enable rate limiting, don't have this value if you don't wish to rate limit.ANIWATCH_API_REDIS_CONN_URL: This env is optional by default and can be set to utilize Redis caching functionality. It has to be a valid connection URL; otherwise, the Redis client can throw unexpected errors.ANIWATCH_API_S_MAXAGE: Specifies the maximum amount of time (in seconds) a resource is considered fresh when served by a CDN cache.ANIWATCH_API_STALE_WHILE_REVALIDATE: Specifies the amount of time (in seconds) a resource is served stale while a new one is fetched.[!CAUTION]
For personal deployments:
- If you want to have rate limiting in your application, then set the
ANIWATCH_API_HOSTNAMEenv to your deployed instance's hostname; otherwise, don't set or have this env at all. If you set this env to an incorrect value, you may face other issues.- It's optional by default, but if you want to have endpoint response caching functionality, then set the
ANIWATCH_API_REDIS_CONN_URLenv to a valid Redis connection URL. If the connection URL is invalid, the Redis client can throw unexpected errors.- You may or may not wanna remove the last
ifblock within the IIFE in theserver.tsfile. It is for render free deployments only, as their free tier has an approx 10 or 15 minute sleep time. Thatifblock keeps the server awake and prevents it from sleeping. You can enable the automatic health check by setting the environment variablesANIWATCH_API_HOSTNAMEto your deployment's hostname, andANIWATCH_API_DEPLOYMENT_ENVtorenderin your environment variables. If you are not using render, you can remove thatifblock.- If you are using a serverless deployment, then set the
ANIWATCH_API_DEPLOYMENT_ENVenv tovercelorrenderorcloudflare-workersdepending on your deployment platform. This is because the API uses this env to configure different functionalities, such as rate limiting, graceful shutdown or hosting static files.
Deploy your own instance of Aniwatch API on Vercel.
[!NOTE]
When deploying to vercel, you must set the env named
ANIWATCH_API_DEPLOYMENT_ENVtovercelfor proper functioning of the API.
Deploy your own instance of Aniwatch API on Render.
[!NOTE]
When deploying to render, you must set the env named
ANIWATCH_API_DEPLOYMENT_ENVtorenderfor proper functioning of the API.
The endpoints exposed by the api are listed below with examples that uses the Fetch API, but you can use any http library.
GET Anime Home Page/api/v2/hianime/home
const resp = await fetch("/api/v2/hianime/home");
const data = await resp.json();
console.log(data);
{
success: true,
data: {
genres: ["Action", "Cars", "Adventure", ...],
latestEpisodeAnimes: [
{
id: string,
name: string,
poster: string,
type: string,
episodes: {
sub: number,
dub: number,
}
},
{...},
],
spotlightAnimes: [
{
id: string,
name: string,
jname: string,
poster: string,
description: string,
rank: number,
otherInfo: string[],
episodes: {
sub: number,
dub: number,
},
},
{...},
],
top10Animes: {
today: [
{
episodes: {
sub: number,
dub: number,
},
id: string,
name: string,
poster: string,
rank: number
},
{...},
],
month: [...],
week: [...]
},
topAiringAnimes: [
{
id: string,
name: string,
jname: string,
poster: string,
},
{...},
],
topUpcomingAnimes: [
{
id: string,
name: string,
poster: string,
duration: string,
type: string,
rating: string,
episodes: {
sub: number,
dub: number,
}
},
{...},
],
trendingAnimes: [
{
id: string,
name: string,
poster: string,
rank: number,
},
{...},
],
mostPopularAnimes: [
{
id: string,
name: string,
poster: string,
type: string,
episodes: {
sub: number,
dub: number,
}
},
{...},
],
mostFavoriteAnimes: [
{
id: string,
name: string,
poster: string,
type: string,
episodes: {
sub: number,
dub: number,
}
},
{...},
],
latestCompletedAnimes: [
{
id: string,
name: string,
poster: string,
type: string,
episodes: {
sub: number,
dub: number,
}
},
{...},
],
}
}
GET Anime A-Z List/api/v2/hianime/azlist/{sortOption}?page={page}
| Parameter | Type | Description | Required? | Default |
|---|---|---|---|---|
sortOption |
string | The az-list sort option. Possible values include: "all", "other", "0-9" and all english alphabets . | Yes | -- |
| Parameter | Type | Description | Required? | Default |
|---|---|---|---|---|
page |
number | The page number of the result. | No | 1 |
const resp = await fetch("/api/v2/hianime/azlist/0-9?page=1");
const data = await resp.json();
console.log(data);
$ claude mcp add TatakaiAPI \
-- python -m otcore.mcp_server <graph>