Creates a new AniLink instance. The authToken parameter is optional and only
required for authenticated queries and mutations; without it only public queries are
available. Multiple instances can hold different authTokens, each exposing an
AniListApi under anilist and a MyAnimeListApi under mal.
Alternatively, pass a per-provider AniLinkCredentials object: each provider owns its own credentials shape, and credentials given under one key are never applied to another provider's requests.
OptionalauthToken: string | AniLinkCredentials
The authentication token to use for AniList API requests, or a per-provider credentials object ({ anilist?: ..., mal?: ... }).
Optionaloptions: RequestOptions
Transport settings scoped to this instance: timeout, signal cancellation, automatic retries under the default policy (retry: false opts out), paceWithRateLimit pacing (on by default), opt-in circuitBreaker fast-fail, the onError/onRetry/onRequestStart/onResponse observability hooks, and exposeRawAxiosError debugging. In the legacy (token, options) form, these settings apply only to AniList. Configure MAL transport settings in the credentials-object form under mal. Options never leak between instances. Only valid when the first argument is a token string or omitted; combining a credentials object with a second argument throws, because the credentials form carries its own per-provider transport settings and a second argument would be silently dropped.
When a per-provider credentials object is combined with a second options argument. The credentials form carries transport settings inside each provider slot, so the second argument would be silently ignored. The constructor rejects the ambiguous call instead.
const aniLink = new AniLink('authToken');
const aniLink2 = new AniLink();
// Per-instance transport settings:
const tuned = new AniLink('authToken', {
timeout: 10_000,
retry: false, // opt out of the default retry policy
onResponse: ({ url, durationMs }) => console.log(url, durationMs),
});
// Per-provider credentials (each provider keeps its own token):
const multi = new AniLink({
anilist: { authToken: 'anilist-token', timeout: 5_000 },
mal: { accessToken: 'mal-token' },
});
The AniList GraphQL API, a AniListApi composed from the query, mutation, custom, and helper groups.
The MyAnimeList REST API methods, a MyAnimeListApi exposed under the mal namespace.
Returns a read-only, point-in-time snapshot of each provider client's shared transport state: the circuit-breaker scopes, retry-budget window, rate-limit pacing deadlines keyed through that client's state owner, and (when the provider's transport options enable a response cache) the cache's live entry count and lifetime hit/miss/expiration/eviction counters. Callers can check whether a breaker is open, how many budget retries are spent, when pacing ends, and how the cache performs without wiring lifecycle hooks and without holding the ResponseCache instance.
Each provider's snapshot is built by snapshotTransportState, which owns the read-only contract. It returns deep-frozen copies that never alias or mutate the live state, so polling on a schedule is safe alongside live traffic.
A frozen per-provider TransportStateSnapshot pair:
{ anilist: {...}, mal: {...} }. Each snapshot carries capturedAt,
the epoch-millisecond build time, so a polled snapshot records when
it was taken.
const aniLink = new AniLink("token", {
circuitBreaker: { threshold: 5, cooldownMs: 30_000 },
});
// After some traffic:
const state = aniLink.getTransportState();
for (const breaker of state.anilist.circuit) {
console.log(
breaker.host,
breaker.openedAt === null ? "closed" : `open since ${breaker.openedAt}`,
`failures: ${breaker.consecutiveFailures}`
);
}
if (state.anilist.retryBudget) {
console.log("budget retries spent:", state.anilist.retryBudget.retriesUsed);
}
for (const deadline of state.anilist.paceDeadlines) {
console.log("pacing until", new Date(deadline.deadlineMs).toISOString(), "for", deadline.host);
}
if (state.anilist.responseCache) {
console.log("cache entries:", state.anilist.responseCache.entries);
}
AniLink is the public entry point for interacting with the AniList GraphQL and MyAnimeList REST APIs. A single instance composes an AniListApi (under
anilist) and a MyAnimeListApi (undermal), each keeping its own credentials and transport settings.